gpt4 book ai didi

android - 如何在android中的谷歌地图上绘制动态旅行路径

转载 作者:行者123 更新时间:2023-11-29 17:43:55 25 4
gpt4 key购买 nike

i have integrated google map in android. and i am getting current location using GPS. on Onlocationchanged i am updating the current location.

My doubt is i am on the Google map UI . i wants to walk or drive that time from my current location as starting point and i wants to start draw the line on map dynamically.

i searched on net for long time but i am not getting any solution . here is my code please anyone help me to over come this problem.

private void initalizeMap()
{
// Google Play Services are available
// Getting GoogleMap object from the fragment
googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();

if(gps.canGetLocation())
{
double latitude = Double.valueOf(Helper.loadSavedPreferences(getActivity(), NameConversion.LATITUDE));
double longtitude = Double.valueOf(Helper.loadSavedPreferences(getActivity(), NameConversion.LONGITUDE));

Log.d("getting gps value", ""+ latitude);
Log.d("getting gps Long", ""+ longtitude);
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longtitude);
// create marker
marker = new MarkerOptions().position(latLng).title("You are here!");
// Changing marker icon
// set yours icon here
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_green_point));
// Showing the current location in Google Map
googleMap.setTrafficEnabled(true);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));
googleMap.addMarker(marker);
}else{
Toast.makeText(getActivity(), "failed To get the location", Toast.LENGTH_SHORT).show();
}
}

@Override
public void onLocationChanged(Location location) {

double latitude = gps.getLatitude();
// Getting longitude of the current location
double longitude = gps.getLongitude();
// Creating a LatLng object for the current location

Log.d("latitude map Class", "latitude: " + gps.getLatitude());
Log.d("longitude Map CLass", "longitude: " + gps.getLongitude());

LatLng latLng = new LatLng(latitude, longitude);
// create marker
MarkerOptions marker = new MarkerOptions().position(latLng).title("You are here!");
// Changing marker icon
// set yours icon here
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_green_point));
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));

}

and i tried with following links [1 st lnikn second link

最佳答案

要在 Google map 上获取驾车或步行时间,您必须使用 Google 提供的 Direction API。方向的 API 调用将是这样的:

http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los%20Angeles,CA&sensor=false

并且您可以将其嵌入到一个类中,在该类中您将使用 AsyncTask 进行 http 调用,如下所示:

GenericUrl url = new GenericUrl("http://maps.googleapis.com/maps/api/directions/json");
url.put("origin", origin);
url.put("destination", destination);
url.put("sensor",false);

请关注这个tutorialthis以便获取方向 API(包括 map 上的驾车、公交、步行和骑自行车方向。)

希望对您有所帮助!!!

关于android - 如何在android中的谷歌地图上绘制动态旅行路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27738147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com