在iOS sdk中使用GPS进行逐步导航

时间:2014-04-24 05:44:49

标签: ios google-maps gps

我希望通过使用带谷歌地图的GPS以及如何实现这一目标来逐步导航。

任何帮助真的很感激

谢谢

1 个答案:

答案 0 :(得分:2)

您需要一个Google API服务,当您提供Startpoint和Destination指向并使用以下内容调用api时,它们会提供完整的路径路径

http://maps.google.com/maps/api/directions/json?sensor=true&origin=23.027439,72.523089&destination=23.029108,72.507570

这里我的起点是origin = 23.027439,72.523089而destintaion是destination = 23.029108,72.507570

所以现在谷歌将提供以下数据

{
   "routes" : [
      {
         "bounds" : {
            "northeast" : {
               "lat" : 23.0296906,
               "lng" : 72.5234184
            },
            "southwest" : {
               "lat" : 23.026354,
               "lng" : 72.50715599999999
            }
         },
         "copyrights" : "Map data ©2014 Google",
         "legs" : [
            {
               "distance" : {
                  "text" : "2.2 km",
                  "value" : 2249
               },
               "duration" : {
                  "text" : "5 mins",
                  "value" : 325
               },
               "end_address" : "Sarkhej - Gandhinagar Highway, Satellite, Ahmedabad, Gujarat 380054, India",
               "end_location" : {
                  "lat" : 23.0290924,
                  "lng" : 72.5076297
               },
               "start_address" : "38, Indus Park, Satellite, Ahmedabad, Gujarat 380015, India",
               "start_location" : {
                  "lat" : 23.027439,
                  "lng" : 72.5230894
               },
               "steps" : [
                  {
                     "distance" : {
                        "text" : "68 m",
                        "value" : 68
                     },
                     "duration" : {
                        "text" : "1 min",
                        "value" : 24
                     },
                     "end_location" : {
                        "lat" : 23.0269233,
                        "lng" : 72.5227287
                     },
                     "html_instructions" : "Head \u003cb\u003esouthwest\u003c/b\u003e toward \u003cb\u003eSatellite Rd\u003c/b\u003e",
                     "polyline" : {
                        "points" : "oppkCitsyLXPJFh@\\VN"
                     },
                     "start_location" : {
                        "lat" : 23.027439,
                        "lng" : 72.5230894
                     },
                     "travel_mode" : "DRIVING"
                  },
                  {
                     "distance" : {
                        "text" : "85 m",
                        "value" : 85
                     },
                     "duration" : {
                        "text" : "1 min",
                        "value" : 30
                     },
                     "end_location" : {
                        "lat" : 23.0265039,
                        "lng" : 72.5234184
                     },
                     "html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eSatellite Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Hanuman Mandir (on the left)\u003c/div\u003e",
                     "maneuver" : "turn-left",
                     "polyline" : {
                        "points" : "gmpkCarsyLVa@`@u@Pc@FM"
                     },
                     "start_location" : {
                        "lat" : 23.0269233,
                        "lng" : 72.5227287
                     },
                     "travel_mode" : "DRIVING"
                  },

您必须了解使用Google方向服务的文档,其中包含https://developers.google.com/maps/documentation/javascript/directions链接。

这是一个简单的逻辑,你可以在那之后使用。

你要做的就是将这个步骤存储在arrayArray数组中,然后尝试逐个获取它。 检查当前Lat Long的didUpdateToLocation方法,如果当前位置靠近步​​骤Dcitionay的endLocation点的值,如果它接近,那么你可以提醒html_instructions的消息值用户必须去哪个方向并增加步骤数组字典的索引和最后一个步骤索引的索引。

如果需要任何帮助,请随时询问。