2016-06-08 95 views
0

我們將在地圖上繪製的折線與谷歌地圖應用中的折線不相似。它給人一種很好的3D感覺,我們可以繪製與該折線相似的折線嗎?。是否可以使用9貼片圖像?任何人都可以幫忙嗎?如何在android中繪製類似google map app的折線?

+0

不,它是不可能的。事實上,GoogleMaps並不是像我們一樣使用播放服務API,但他們有更多的方法可供使用。 –

回答

0

你好,這會幫助你,它幫助了我。

首先從Google開發者帳戶製作google api服務器密鑰,然後爲Google方向添加依賴項。

compile 'com.akexorcist:googledirectionlibrary:1.0.4' 

然後它檢查LatLongs之間的可行和最短路線。

使用此代碼檢查路線是否可用。

GoogleDirection.withServerKey(getResources().getString(R.string.SERVER_KEY)) 
        .from(SourceLatlng) 
        .to(DestinationLatlng) 
        .execute(new DirectionCallback() { 
         @Override 
         public void onDirectionSuccess(Direction direction, String message) { 
          if (direction.isOK()) { 
           DrawRoute(direction, message,SourceLatlng,DestinationLatlng); 
          } else { 
           //selectedRawLine = ERROR; 
          } 

         } 

         @Override 
         public void onDirectionFailure(Throwable t) { 
          t.printStackTrace(); 
         } 
        }); 

利用這個我們可以發現這條路線是可行與否

private void DrawRoute(Direction direction, String message,LatLng sourceLatlng,LatLng DestinationLng) { 

     for (Route route : direction.getRouteList()) { 
      PolylineOptions polyoptions = new PolylineOptions(); 
      polyoptions.color(getResources().getColor(R.color.blackcolor)); 
      polyoptions.width(5); 
      polyoptions.addAll(route.getOverviewPolyline().getPointList()); 
      poly = googleMap.addPolyline(polyoptions); 
      poly.setClickable(true); 

     } 
     LatLngBounds.Builder latLngBuilder = new LatLngBounds.Builder(); 
     if(sourceLatlng!=null) 
     latLngBuilder.include(sourceLatlng); 
     if(DestinationLng!=null) 
     latLngBuilder.include(DestinationLng); 

     try { 
      LatLngBounds bounds = latLngBuilder.build(); 
      CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 
        UiHelper.dpToPixel(getActivity(), 135)); 
      googleMap.animateCamera(cu); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 

使用此代碼,我們提出兩個latLongs之間折線...

+0

我試過多行,但谷歌地圖的(系統應用程序)多邊形線不同於此折線 –

+0

您可以更改多邊形線的顏色與地圖多段線相同,並使用此更改多段線的寬度。 –

+0

polyoptions.width(5); –