nitwatar
nitwatar

Reputation: 169

How to show multiple Location on Google map?

i have to show multiple location on the Native Google Map Application (MapView is not implemented in our application ).i have all the lat- long of all the geo Points . how can i pass the intent to show the multiple points on Native Google Map Application.

i know to show a point on Google map using the following Code.

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);

please suggest how to do the needful changes.

Thanks :)

Upvotes: 2

Views: 3473

Answers (2)

Saumik Bhattacharya
Saumik Bhattacharya

Reputation: 941

You can pass the names of the places that you want to show in the Map from the other Activity to the present Activity and then implement Markers to show them in the Map. For this you have to implement Google Map in the present Activity and I hope you have done that. :)

The below code shows multiple locations on a Google Map:

private void AddMarkers(GoogleMap googleMap)
{
    try {
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        Geocoder geocoder = new Geocoder(context);
        Origin_Map = extras.getString(MainActivity.ORIGIN_MAP);
        Destination_Map = extras.getString(MainActivity.DESTINATION_MAP);
        Addr_Origin = geocoder.getFromLocationName(Origin_Map, 1);
        Addr_Dest = geocoder.getFromLocationName(Destination_Map, 1);
        if (Addr_Origin.size() > 0) {
            latitude_origin = Addr_Origin.get(0).getLatitude();
            longitude_origin = Addr_Origin.get(0).getLongitude();
        }
        if (Addr_Dest.size() > 0) {
            latitude_destination = Addr_Dest.get(0).getLatitude();
            longitude_destination = Addr_Dest.get(0).getLongitude();
        }
        Marker m1 = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude_origin, longitude_origin)).title(Origin_Map).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
        Marker m2 = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude_destination, longitude_destination)).title(Destination_Map).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

    } catch (Exception e) {
        e.printStackTrace();
    }
}

And call this method once your map is ready!

@Override
public void onMapReady(GoogleMap googleMap)
{
    AddMarkers(googleMap);
}

Hope this helps!!

Upvotes: 1

ddog
ddog

Reputation: 670

Judging by this it is not possible. Also the question is a duplicate of this.

Upvotes: 0

Related Questions