2015-12-15 25 views
3

我想提请使用的谷歌Android map.I两个位置之间的路径已经厌倦了这段代码如何得出两个位置的android

PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true); 

     if (cursor.moveToFirst()) { 
      do { 

       // latitude and longitude 
       double latitude = 0.00; 
       double longitude = 0.00; 


       Log.i("lat", cursor.getString(10)); 
       Log.i("lat", cursor.getString(11)); 


       try { 
        latitude = Double.parseDouble(cursor.getString(10)); 
       } catch (Exception e) { 

       } 

       try { 
        longitude = Double.parseDouble(cursor.getString(11)); 
       } catch (Exception e) { 

       } 
       if (latitude == 0.00 || longitude == 0.00) { 

       } else { 
        i++; 





         LatLng point = new LatLng(latitude,longitude); 
         options.add(point); 



        // create marker 
        MarkerOptions marker = new MarkerOptions().position(
          new LatLng(latitude, longitude)).title(cursor.getString(1)); 

       } 

      } 
      while (cursor.moveToNext()); 
     } 
     cursor.close(); 


     googleMap.addPolyline(options); 

,但我得到直line.like这

之间实际道路路

my map view

我想在实际道路上获得路径。

谢谢.. !!

回答

1

如果你想画2点和沿路之间的折线,你可以与图书馆尝试Google-Directions-Android

您可以compile 'com.github.jd-alexander:library:1.0.7'

的gradle上添加库可以使用所有的点(经纬度),并利用它们进入航点方法。

Routing routing = new Routing.Builder() 
       .travelMode(/* Travel Mode */) 
       .withListener(/* Listener that delivers routing results.*/) 
       .waypoints(/*waypoints*/) 
       .build(); 
    routing.execute(); 
+0

我可以使用相同的代码吗? –

+0

是的。你正在做的是获得你的所有观点(Latlng),并把它们放到路点方法中。 – xiaomi

+0

虽然gradle building显示错误 –

0

请检查这个答案,让我知道,如果这是你所需要的:

https://stackoverflow.com/a/17007360/2027644

+0

给我一个错误 –

+0

请详细说明错误 –

+0

错误是谷歌服务器中未发现java.io.FileNotFoundException:http://maps.googleapis.com/maps/api/directions/json –