我想在 map 上画出与方向JSON相对应的路由,我正在通过Google directions API:https://developers.google.com/maps/documentation/directions/start获取这些路由
I have figured out how to extract the latitude and longitude from the steps field, however this doesn't follow curvy roads very well. I think what I need is to decode the polyline information, I found Googles instructions on how to encode polylines: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
I did find some code here for Android and also Javascript on decoding the polylines, for example:
Map View draw directions using google Directions API - decoding polylines个
android get and parse Google Directions
但我找不到同样的Objective-C iPhone代码,有人能帮我吗?如果有必要的话,我相信我可以自己做,但如果已经有地方可以使用的话,这肯定会节省我一些时间.
编辑:这里的关键是能够逐个字符地解码base64编码.更具体地说,我从谷歌的JSON中得到了类似的东西,它是使用base64编码进行编码的:
... "overview_polyline" : {
"points" : "ydelDz~vpN_@NO@QEKWIYIIO?YCS@WFGBEBICCAE?G@y@RKBEBEBAD?HTpB@LALALCNEJEFSP_@LyDv@aB\\GBMB"
},
...
注意:我应该提一下这个问题是指Google Maps API v1,使用GMSPolyLine polyLineWithPath在v2中做这件事要容易得多,因为下面的许多答案都会告诉您(感谢@cdesCours).