2016-03-10 43 views
-1

enter image description here显示路线和地图图标默认 - Mapfragment的Android

嗨,
1.请找到高亮区域的路线和地图图标。
2.这些显示在我的位置蓝色圆圈上。
3.希望在地图加载后默认显示这些图标,而无需用户触摸。

下面是代码:

protected void loadMap(GoogleMap googleMap, String latlng) { 
     if (googleMap != null) { 
      googleMap.setMyLocationEnabled(true); 
      googleMap.getUiSettings().setMapToolbarEnabled(true); 
      googleMap.getUiSettings().setMyLocationButtonEnabled(true); 
      String[] latlngAry = latlng.split(","); 
      double lat = Double.parseDouble(latlngAry[0]); 
      double lng = Double.parseDouble(latlngAry[1]); 
      LatLng latlong = new LatLng(lat, lng); 

      BitmapDescriptor defaultMarker = 
        BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE); 

      Marker marker = googleMap.addMarker(new MarkerOptions() 
        .position(latlong) 
        .title("My Location") 
        .icon(defaultMarker)); 


      marker.showInfoWindow(); 
      googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlong, 18)); } 
+0

您可以接受我的回答因为这是一个合适的答案。 –

回答

1

点击标记时出现的叠加,创建并隐含销毁现场。您不能手动显示(还)。

如果必须使用此功能,您可以创建在你的地图覆盖2个ImageViews,并调用相应的意图他们点击后:

// Directions 
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
     "http://maps.google.com/maps?saddr=51.5, 0.125&daddr=51.5, 0.15")); 
startActivity(intent); 
// Default google map 
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
     "http://maps.google.com/maps?q=loc:51.5, 0.125")); 
startActivity(intent); 

注意:您需要更改基于坐标标记的getPosition()和用户的位置。

现在要隐藏默认覆盖图,您只需在OnMarkerClickListener中返回true即可。尽管你没有能力在标记上显示InfoWindows和中心相机,但你可以很简单地模仿:

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { 
    @Override 
    public boolean onMarkerClick(Marker marker) { 
     marker.showInfoWindow(); 
     mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition())); 
     return true; 
    } 
});