Android Google Maps resize marker on Zoom

前端 未结 3 1628
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 21:15

I need to display around 30 markers in a somewhat small area.

Is there a way to resize Google Maps API V2 markers when the user changes the zoom?

Or should I jus

相关标签:
3条回答
  • 2021-01-21 21:40

    I use extends and fitBounds functions and get positions (LatLng) to set a zoom to map items

    //JSP
    
    <c:forEach var="lastPosition" items="${lastPositionResultDto}" >        
        <input type="hidden" id="mapPointsPosition_${lastPosition.id}" value="${lastPosition.latitude}_${lastPosition.longitude}" >
    </c:forEach>
    
    
    //JAVASCRIPT
    
    map = new google.maps.Map(document.getElementById('map-canvas-position'), mapOptions);    
    
    var arrPointMaps = $("[id^=mapPointsPosition_]");
    var limits = new google.maps.LatLngBounds(0,0);
    
    for(var j=0; j<arrPointMaps.length;  j++){
    
        var stringPointMap = arrPointMaps[j].getAttribute("value").split("_");
        var latAlertPoint = stringPointMap[0];
        var lonAlertPoint = stringPointMap[1];                
    
        var limitPosition = new google.maps.LatLng(parseFloat(latAlertPoint), parseFloat(lonAlertPoint));
        limits.extend(limitPosition);
    
    }   
    
    map.fitBounds(limits); 
    
    }
    
    0 讨论(0)
  • 2021-01-21 21:55

    If you want to do something when zooming, you can create a custom Mapview which extends the original MapView, and just override dispatchDraw(Canvas canvas).

    With adding a little listener, you can do whatever you want in the callback. Something like this;

        @Override
    protected void dispatchDraw(final Canvas canvas) {
        super.dispatchDraw(canvas);
        if (getZoomLevel() != lastZoomLevel) {
            if (listener != null) {
                listener.onZoom(lastZoomLevel, getZoomLevel());
            }
            lastZoomLevel = getZoomLevel();
        }         
    }
    
    0 讨论(0)
  • 2021-01-21 21:56

    There is no an outOfTheBox option to change the icons for the markers. you will have to listen to zoom changes:

    How to listen for user generated zoom in Google Maps?

    and to remove the older markers and set new ones in their location with smaller icon images.

    0 讨论(0)
提交回复
热议问题