Reputation: 137
I have to show route between two locations using google map, but i am getting just straight line between two location, I am using below code
- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(@(-33.860).doubleValue,@(151.208).doubleValue)];
[path addCoordinate:CLLocationCoordinate2DMake(@(-32.860).doubleValue,@(150.208).doubleValue)];
GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
rectangle.strokeWidth = 2.f;
rectangle.map = mapView_;
self.view = mapView_;
}
Please tell me how to do this, i have seen various previous this type question but not getting. Please help me... Any help will be appreciated...
Upvotes: 0
Views: 291
Reputation: 18242
This doesn't work this way. You are adding only two coordinates to your GMSMutablePath
, so the resulting GMSPolyline
is a straight line.
If you want to get routes between two points you will need to use a directions API such as Google Maps Directions API that calculates directions between locations using an HTTP request.
Upvotes: 1