【问题标题】:how to draw path between 2 points on google map如何在谷歌地图上绘制两点之间的路径
【发布时间】:2017-02-08 20:13:23
【问题描述】:

我一直在开发一个使用谷歌地图的安卓应用程序。现在我想在地图上生成两点之间的路径(行车方向),怎么做?

【问题讨论】:

标签: android google-maps


【解决方案1】:
【解决方案2】:
public  void DrawLine(LatLng location){
    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.add(location)
    .add(new LatLng(mlatitude, mlongitude))
            .add(new LatLng(mlatitudeEnd,mlongitudeEND));
         mMap.addPolyline(polylineOptions);


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

}

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

@Override
protected void onStop() {
    mGoogleApiClient.disconnect();
    super.onStop();
}

@Override
public void onLocationChanged(Location location) {
    mLastLocation = location;     
}


protected void placeMarkerOnMap(LatLng location){
    MarkerOptions markerOptions=new MarkerOptions().position(location);
    String str_getloc = getAddress(location);
    markerOptions.title(str_getloc);
    mMap.addMarker(markerOptions);
}
private String getAddress(LatLng location){
    Geocoder geocoder=new Geocoder(this);
    String addresstxt="";
    List<Address> addresses=null;
    Address address=null;

    try {
        addresses=geocoder.getFromLocation(location.latitude,location.longitude,1);
        //addresstxt= String.valueOf((new LatLng(mlatitude,mlongitude)));
        //addresses.add(addresstxt)
        if (null != addresses && !addresses.isEmpty() ){
            address=addresses.get(0);
            for (int i=0; i<address.getMaxAddressLineIndex();i++){
                addresstxt += (i==0) ?address.getAddressLine(i): ("\n"+address.getAddressLine(i));

            }
            if (mlatitudeEnd!=0.0&&mlongitudeEND!=0.0){
                Toast.makeText(this, "if", Toast.LENGTH_SHORT).show();
                // DrawLine(new LatLng(mlatitude,mlongitude));
                DrawLine(location);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return addresstxt;
}

【讨论】:

  • 感谢您分享您的答案。你能添加一个解释或一些cmets吗?
猜你喜欢
  • 2017-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-04
相关资源
最近更新 更多