【问题标题】:Draw the driving path in map according PlaceAutocompleteFragement input of source and destination Android根据源和目的地Android的PlaceAutocompleteFragement输入在地图中绘制行车路径
【发布时间】:2018-04-19 04:19:18
【问题描述】:

第一次写安卓项目。而我面临的一个问题是。我从 PlaceAutocompleteFragement 获得了源和目标信息。但是,我不知道如何在地图中绘制它们。我看过一些文章,例如在地图中通过 2 个地方绘制路径,但大多数时候是通过单击地图中的一个地方直接标记该点,而不是从文本框中获取该位置。谁能帮我。非常感谢。

【问题讨论】:

  • youtube.com/watch?v=CCZPUeY94MU&t=743s 跳到 24:05 秒并检查是否是您想要的。
  • 这个视频和我的想法很相似。我可以将源和目标的文本框输入替换为 PlaceAutocompleteFragement 吗? @AswinPAshok
  • 我对 PlaceAutocompleteFragment 不熟悉。但是,如果您可以从 PlaceAutocompleteFragment 获取地名/位置的 LatLng,您可以修改该教程以满足您的需要。
  • https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&key=YOUR_API_KEY 这是谷歌方向请求网址的样子。注意 url 中的 origindestination。如果你能得到这样的地名,你可以得到沿该路线的所有必需的 LatLngs 并绘制折线路径。起点和终点也可以是经纬对。
  • 查看 developers.google.com/maps/documentation/directions 了解更多关于方向 api 的信息

标签: android google-maps path placeautocompletefragment


【解决方案1】:

看看这个,

初始化谷歌地图后,获取两个位置之间的 Latlngs 列表,然后将这些 Latlngs 添加到谷歌地图中,​​如下所示。

PolylineOptions options = new 
PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
for (int z = 0; z < latLnglist.size(); z++) {
LatLng point = latLnglist.get(z);
options.add(point);
}
line = myMap.addPolyline(options);

【讨论】:

  • 将地点经纬度存入List?
猜你喜欢
  • 1970-01-01
  • 2011-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多