2016-03-10 66 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; 
    } 
});