0

我刚刚使用此代码在 Google Map 中的位置之间显示了一条路径。

   double srclat=8.8854;
   double srclong=76.5833;
   double destlat=9.0544;
   double destlong=76.5353;

  Intent i = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://maps.google.com /maps?saddr="+srclat+","+srclong+"&daddr="+destlat+","+destlong));
    startActivity(i);   

现在我想知道我可以在谷歌地图中绘制路径,比如 A 到 B,然后 B 到 C,然后 C 到 D。使用这种方法或类似的方法

提前致谢

4

1 回答 1

0

我可以使用以下步骤绘制谷歌地图折线:

  1. 在 Android 上实现 Google Map v2(显然)
  2. 从此链接http://maps.googleapis.com/maps/api/directions/json获取来自 google 路线 API 的 JSON 响应(尝试谷歌搜索一些文档或示例),

    指定起始 lat-long 和目标 lat-long,例如: follow this link,结果是 JSON 响应,您可以使用This JSON Formatter在线阅读

  3. 解析 JSON 响应,它有一个名为 的 JSON 对象overview polyline,其中包含您需要绘制的折线数据。
  4. 抓取points里面的数据overview_polyline
  5. 使用此方法绘制折线:

    Map.addPolyline(new polylineOptions().addAll(decodePolyLine(polyline)))

如果正确实施,您应该能够成功绘制折线。请尝试阅读一些文档,它确实有帮助:)

祝你好运^^

于 2013-05-28T02:33:09.620 回答