2016-02-13 145 views
1

我必须在原生Google Map应用程序上显示多个位置(MapView未在我们的应用程序中实现).i拥有所有地理点的所有经纬度。我如何通过意图在本地Google Map应用程序上显示多个点。如何在Google地图上显示多个位置?

我知道使用下面的代码在Google地图上显示一个点。

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

请建议如何做必要的更改。

谢谢:)

+0

我不知道你为什么需要这个。 AFAIK直到现在还不可能。可能的解决方案是将谷歌地图集成到您的应用程序中,以便您可以在地点添加多个标记 –

回答

0

来看由this这是不可能的。此外,问题是this的重复。

0

您可以将要显示在地图中的地点的名称从其他活动传递到当前活动,然后实施标记以在地图中显示它们。为此,您必须在本活动中实施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(); 
    } 
} 

而且调用此方法,一旦你的地图是准备好了!

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

希望这有助于!

+0

亲爱的Saumik,我不在自己的应用程序中显示地图,我只是想在Google Map中显示地图上的所有位置应用程序,因为我已经提到。 – Incognito

相关问题