如何从Google Maps Directions Api获取折线

时间:2017-03-28 11:29:04

标签: android json google-maps directions

我正在尝试使用Google Maps Directions Api绘制,但如何使用JSON值来实现此目的,因为在api中,有很多lat和long和折线。这样点:

  

cxwnFtdct @ JEVGLCR?PDTFNHTNNNPJPDRDN?JCHCv @ I @ VQTK`CkF

我不知道应该使用哪一个,任何人都可以帮助我:)

{
  geocoded_waypoints: [
    {},
    {}
  ],
  routes: [
    {
      bounds: {
        northeast: {
          lat: 39.2846595,
          lng: -8.7036795
        },
        southwest: {
          lat: 38.7223249,
          lng: -9.1393372
        }
      },
      copyrights: "Dados do mapa ©2017 Google, Inst. Geogr. Nacional",
      legs: [
        {
          distance: {},
          duration: {},
          end_address: "Lisboa, Portugal",
          end_location: {
            lat: 38.7223249,
            lng: -9.1393372
          },
          start_address: "Santarém, Portugal",
          start_location: {
            lat: 39.2846595,
            lng: -8.7049071
          },
          steps: [
            {
              distance: {},
              duration: {},
              end_location: {
                lat: 39.2822117,
                lng: -8.7036403
              },
              html_instructions: "Siga <b>sul</b> em direção a <b>N3</b>",
              polyline: {
                points: "cxwnFtdct@JEVGLCR?PDTFNHTNNNPJPDRDN?JCHCv@i@VQTK`CkF"
              },
              start_location: {
                lat: 39.2846595,
                lng: -8.7049071
              },
              travel_mode: "DRIVING"
            },
            {},
          ],
          traffic_speed_entry: [],
          via_waypoint: []
        }
      ],
      overview_polyline: {   points:"cxwnFtdct@dAQlAf@fAf@|Aq@l@]pCcFhCjA|LfJlAT~@IpDi@jAb@f@HXi@t@kBhBeBx@Qz@z@dClHzFpW`H|RvTpj@`AxAdBdAnAXhB?fBk@rAcAnG_HhCgAjAKrATbA`Al@lBHnAc@rFgBhIkCxMBfIlBvHnBtCnB|AnEdCrJxFj@fB@h@OhAgCtHGfCl@jAlA\jE]tDBzBb@tLxFtK~E`d@hShIzEtDhDxDrEfDpFlFjNvDtRdDjThF`TzH`QhEhG|EvFhL`JpJtE|LpEdOpFjOzGlPfJlHzE~NjLfQvPfP|Rt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:2)

答案 1 :(得分:1)

检查Google Maps Android API Utility Library有一些用于解析折线的预定义方法等等。

答案 2 :(得分:0)

我已将答案放在一些包含您答案的帖子中。 你也可以找到Parser类和Aysc类来从地图上的响应中绘制折线。

这是发布的链接 How to buffer a polyline in Android or draw a polygon around a polyline?