开发者

Scaling Android MapView markers when a user zooms in/out [duplicate]

This question already has answers here: On zoom event for google maps on android (10 answers) Closed 2 years ago.

I've seen a few questions about this but no solid answers.

I have a MapView that can generate up to 1600 locations on the map, based on how far the user zooms in or out. As of now, I have my marker simply set to a drawable within my application. How can I detect if a user has zoomed in/out, then scale the marker accordingly. I'm not concerned with the scaling part, but with the zoom listening part. Has anyone developed a solution to this little issue, or can point me in the correct direction to create my own?

Also, as far as I know, there is not a default marker that Android supplies. Am I correct about this? It would be nice if Androi开发者_JS百科d had a built in marker that handles the scaling based on zoom levels for you.


Markers do not change size based on zoom. Use GroundOverlays if you desire this effect. src

 GoogleMap map = ...; // get a map.
 BitmapDescriptor image = ...; // get an image.
 LatLngBounds bounds = ...; // get a bounds
 // Adds a ground overlay with 50% transparency.
 GroundOverlay groundOverlay = map.addGroundOverlay(new GroundOverlayOptions()
     .image(image)
     .positionFromBounds(bounds)
     .transparency(0.5));

A ground overlay is an image that is fixed to a map and scales with the map zoom. Please see the API for more info

See related post: Scale Map Markers by Zoom, Android


I'am use

LatLng latLng = new LatLng(-16.50881576338701,-68.13492067606603);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.raw.ic_car_1);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); 
        googleMap.addGroundOverlay(new GroundOverlayOptions()
             .image(bitmapDescriptor)
             .position(latLng,100));

The docs in google maps docs GroundOverlayOptions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜