Question

I am working on google map v2 and i got a question, i can now add a single marker for my current location and i know the concept about adding markers, but now i want to add more markers which near my current location, and there are thousands of markers can add into the map due to the database

so how can i add markers within a range of area which is surround my current location, and the range will be the user's screen size. Thus more markers when zoom out and less markers when zoom in.

or maybe radius set as 5km of if current location

Thanks guys

marker = map.addMarker(new MarkerOptions().position(
             new LatLng(location.getLatitude(), location.getLongitude()))
             .title("my position").icon(BitmapDescriptorFactory
        .defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
Was it helpful?

Solution

use this approach:

var lat=new_marker.getPosition().lat();
var lng=new_marker.getPosition().lng();

var target = new GLatLng(lat,lng);

var center= new GLatLng(yourLat, yourLng);//your gps position

var distance = center.distanceFrom(target) / 1000;//meters to km

if(distance < radius){//where radius = 5Km
    new_marker.setMap(map);//add to map
}

OTHER TIPS

Look this example is similar that you are looking for, he wants to draw a circle that resize to screen size: Google map api V2 resize screen to match a circle drawn

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top