如何在谷歌地图上使用位置信息创建路线?



我有一个应用程序。我有一个位置信息到谷歌地图。我想从我使用谷歌地图的地方创建一个路径。

String url = "yandexmaps://maps.yandex.ru/?pt=" + routePlan.getLocationLat() + "" + routePlan.getLocationLong() + "&z=12&l=map";
Intent intentYandex = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intentYandex.setPackage("ru.yandex.yandexmaps");
String uriGoogle = "geo:" +routePlan.getLocationLat()+"," + routePlan.getLocationLong();
Intent intentGoogle = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));
intentGoogle.setPackage("com.google.android.apps.maps");
String title = "Select";
Intent chooserIntent = Intent.createChooser(intentGoogle, title);
Intent[] arr = new Intent[1];
arr[0] = intentYandex;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
startActivity(chooserIntent);

谷歌有这方面的服务。您可以使用Google Maps sdk和Google的Directions API

只需向谷歌的方向 api 发送 http 请求即可

https://maps.googleapis.com/maps/api/directions/outputFormat?parameters

它将返回如下所示的 json 响应:

{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJRVY_etDX3IARGYLVpoq7f68",
"types" : [
"bus_station",
"transit_station",
"point_of_interest",
"establishment"
]
},
{
"geocoder_status" : "OK",
"partial_match" : true,
"place_id" : "ChIJp2Mn4E2-woARQS2FILlxUzk",
"types" : [ "route" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 34.1330949,
"lng" : -117.9143879
},
"southwest" : {
"lat" : 33.8068768,
"lng" : -118.3527671
}
},
"copyrights" : "Map data ©2016 Google",
"legs" : [
{
"distance" : {
"text" : "35.9 mi",
"value" : 57824
},
"duration" : {
"text" : "51 mins",
"value" : 3062
},
"end_address" : "Universal Studios Blvd, Los Angeles, CA 90068, USA",
"end_location" : {
"lat" : 34.1330949,
"lng" : -118.3524442
},
"start_address" : "Disneyland (Harbor Blvd.), S Harbor Blvd, Anaheim, CA 92802, USA",
"start_location" : {
"lat" : 33.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gDxCaC`BuJdFkFtCgCnBuClD_HdMqEzHcBpB_C|BuEzCmPlIuE|B_EtDeBhCgAdCw@rCi@|DSfECrCAdCS~Di@jDYhA_AlC{AxCcL`U{GvM_DjFkBzBsB`BqDhBaEfAsTvEmEr@iCr@qDrAiFnCcEzCaE~D_@JmFdGQDwBvCeErEoD|BcFjC}DbEuD~D`@Zr@h@?d@Wr@}@vAgCbEaHfMqA`Cy@dAg@bAO`@gCi@w@W"
},
"summary" : "I-5 N and US-101 N",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}

有用的链接

https://developers.google.com/maps/documentation/directions/intro https://developers.google.com/maps/documentation/android-sdk/start

相关内容

  • 没有找到相关文章

最新更新