javascript google maps API encoding.decodePath返回无效的LatLng

时间:2016-01-22 21:43:32

标签: google-maps-api-3

我使用了javascript API,而且我使用的是从“Strava”(运行应用程序)获得的编码路径。

我的代码如下所示:

var decoded_latlngs = google.maps.geometry.encoding.decodePath('c{|xHbo|OSnFrSjW~M{EnFwVz@wy@vQsq@cBoUzJ{EzObBrIcLfE~C~H{Y~C~CfOgY{EjM{EgTcLzTsSwQcGf@IoKgJSkMsb@RkRvVkRDon@SooBvBsXbGgE{@{EfE{EwLsXgEo{AcVgw@kRc|A_q@seAcLg@bBvQkCnKcGjCwQsSkM?cL{YjHrS{J~HgOwBgOjf@{Jju@cLjRcGz^oUjW{Tni@f@jRsIj\wBjf@sNbo@wG~iArDnlArIj\bGfr@bQf^~WrSnPvVfOjHnURzc@cQbQzc@nUrtAbBfYkC~M~HnZ~Mz^f^_N~MrDbBwQkWsXR{E');

console.log("decoded_latlngs:", decoded_latlngs)

但是我在javascript控制台中收到此错误:

decoded_latlngs: [_.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K]0: _.K1: _.K2: _.K3: _.K4: _.K5: _.K6: _.K7: _.K8: _.K9: _.K10: _.K11: _.K12: _.K13: _.K14: _.K15: _.K16: _.K17: _.K18: _.K19: _.K20: _.K21: _.K22: _.K23: _.K24: _.K25: _.K26: _.K27: _.K28: _.K29: _.K30: _.K31: _.K32: _.K33: _.K34: _.K35: _.K36: _.K37: _.K38: _.K39: _.K40: _.K41: _.K42: _.K43: _.K44: _.K45: _.K46: _.K47: _.K48: _.K49: _.K50: _.K51: _.K52: _.K53: _.K54: _.K55: _.K56: _.K57: _.K58: _.K59: _.K60: _.K61: _.K62: _.K63: _.K64: _.K65: _.K66: _.K67: _.K68: _.K69: _.K70: _.K71: _.K72: _.K73: _.K74: _.K75: _.K76: _.Klength: 77__proto__: Array[0]


leaflet.js:6 Uncaught Error: Invalid LatLng object: (NaN, NaN)

看起来解码不能正常工作。但是,我可以看到编码路径是一个真实的路径(没有拼写错误或错误),通过将它放入这个交互式API,我在地图中得到一个很好的路线:

https://developers.google.com/maps/documentation/utilities/polylineutility?hl=en

关于为什么这不起作用的任何想法?

1 个答案:

答案 0 :(得分:0)

google.maps.LatLngLeaflet.LatLng不同(因为您似乎尝试使用传单中的路径)。

google.maps.LatLng latlng函数(返回特定的浮点数)

LeafLet.LatLng latlng 花车

您必须首先将路径中的google.maps.LatLngs转换为Leaflet.LatLngs,然后才能在Leaflet中使用它们。