2013-01-02 114 views
0

我正在開發與Android Place Locator相關的應用程序,我一直在努力顯示位置(許多位置和自己的位置),但我想顯示任意兩個位置之間的路徑。位置可以是任何兩個。工作了很多,但沒有找到任何解決方案。請提供一些參考資料,以便我可以獲得解決方案。顯示Google地圖中兩個位置之間的路徑(Android)

+0

請參考http:// stackoverflow的.com /問題/ 2176397 /繪圖-A-線路路徑上谷歌-地圖 – 2013-01-02 09:47:40

回答

0
try this code 


    String uri = "http://maps.google.com/maps?saddr=" + 
    currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude; 
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse(uri)); intent.setClassName("com.google.android.apps.maps", 
    "com.google.android.maps.MapsActivity"); startActivity(intent); 

願這幫助你

0

要添加此庫添加依賴於gradle這個作爲

compile 'com.akexorcist:googledirectionlibrary:1.0.4' 

使用此代碼在活動

GoogleDirection.withServerKey("YOUR_SERVER_API_KEY") 
      .from(new LatLng(37.7681994, -122.444538)) 
       .to(new LatLng(37.7749003,-122.4034934)) 
       .avoid(AvoidType.FERRIES) 
       .avoid(AvoidType.HIGHWAYS) 
       .execute(new DirectionCallback() { 
     @Override 
     public void onDirectionSuccess(Direction direction, String rawBody) { 
      if(direction.isOK()) { 
       // Do something 
Snackbar.make(btnRequestDirection, "Success with status : " + direction.getStatus(), Snackbar.LENGTH_SHORT).show(); 
       googleMap.addMarker(new MarkerOptions().position(origin)); 
      googleMap.addMarker(new MarkerOptions().position(destination)); 

      ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint(); 
      googleMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 5, Color.RED)); 

     } 

      } else { 
       // Do something 
      } 
     } 

     @Override 
     public void onDirectionFailure(Throwable t) { 
      // Do something 
     } 
    }); 

它會幫助你,你,它的幫我

相關問題