0

I am building an iOS app that tracks a users location using Google Maps SDK. I am storing any changed lat/long coordinates in an array by checking if the coordinates exist and if they don't exist they get appended.

This is working great when I plot a polyline however I would like to take some of those coordinates and create directions (follow a street, road, path etc).

Is there a way to take say 10 or 20 coordinates and plot directions from those? And once the directions are created, return the lat/long coordinates of the new route?

puks1978
  • 3,667
  • 11
  • 44
  • 103
  • Use this http://stackoverflow.com/questions/28784034/swift-ios-google-map-path-to-coordinate/34435391#34435391 – LC 웃 Dec 23 '15 at 12:11

2 Answers2

0

Yes, you have to call the Google Directions API and pass your coordinates as waypoints. You can also tell the API the order of those waypoints to trace routes. I've done it like this:

http://maps.googleapis.com/maps/api/directions/json?&origin=28.584442,-81.305543&destination=28.596688, -81.302325&waypoints=28.589793,-81.311122|28.595897, -81.308891&sensor=false

Separate each pair of coordinates you want to use as waypoint with a pipe character |

You can learn more on how to use waypoints in routes here:

https://developers.google.com/maps/documentation/directions/#Waypoints

Jorge
  • 1,066
  • 8
  • 16
  • Thanks. I am not sure how to use this in Swift (as I am new to Swift development). Do you have any further references I can read or sample code I could modify? I have been searching around but can't find much in the way of samples. – puks1978 Jul 16 '15 at 01:16
0

Might help someone else

 GMSCameraPosition *cameraPosition=[GMSCameraPosition cameraWithLatitude:13.0733838 longitude:80.19203929 zoom:12];
    _mapView =[GMSMapView mapWithFrame:CGRectZero camera:cameraPosition];
    GMSMarker *marker=[[GMSMarker alloc]init];
    marker.position=CLLocationCoordinate2DMake(13.0733838, 80.19203929);
    marker.icon=[UIImage imageNamed:@"mappinblue"] ;
    marker.groundAnchor=CGPointMake(0.5,0.5);
    marker.map=_mapView;
    GMSMutablePath *path = [GMSMutablePath path];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.0733838).doubleValue,@(80.19203929).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.074099).doubleValue,@(80.1919654).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.070933).doubleValue,@(80.1842051).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.0770034).doubleValue,@(80.21175909999999).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.0784528).doubleValue,@(80.2120139).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.078285).doubleValue,@(80.21424979999999).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.0774898).doubleValue,@(80.21416479999999).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(13.0774401).doubleValue,@(80.2146616).doubleValue)];


    GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
    rectangle.strokeWidth = 4.f;
    rectangle.map = _mapView;
Surender Rathore
  • 845
  • 8
  • 18