decode - Google Maps decoded GMSPath incorrect iOS -


so, use directions api in app. however, when decode polyline response, not show correctly. here code:

    //construct request url     nsstring *urlstring = [nsstring stringwithformat:                            @"%@?origin=%f,%f&destination=%f,%f&sensor=true&key=%@",                            @"https://maps.googleapis.com/maps/api/directions/json",                            usermarker.position.latitude,                            usermarker.position.longitude,                            place.coordinate.latitude,                            place.coordinate.longitude,                            @"aizasydrtha-amivvylupcp46_vf1ezjjfbwrcy"];      nsurl *directionsurl = [nsurl urlwithstring:urlstring];       //get directions in json format     dispatch_async(dispatch_get_main_queue(), ^{         nsdata* data = [nsdata datawithcontentsofurl:directionsurl];          nserror* error;          if(data){             nsdictionary *json = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error];              //parse json , plot route on map             nsdictionary *routes = [json objectforkey:@"routes"][0];              nsdictionary *route = [routes objectforkey:@"overview_polyline"];             nsstring *overview_route = [route objectforkey:@"points"];              //clear map previous polylines             [self.mapview clear];              //make polyline             gmspath *path = [gmspath pathfromencodedpath:overview_route];             gmspolyline *polyline = [gmspolyline polylinewithpath:path];             polyline.strokewidth = 4;             polyline.strokecolor = [uicolor darkgraycolor];             polyline.map = self.mapview; }); 

and here polyline:

enter image description here

as can,see not follow road properly. however, me seems if there not enough points have proper bends.

edit: happens 50% of time, shows correctly, not.

what doing wrong?

going (which using js api instead of json api you're using):

get polyline google maps directions v3

it looks should use lines in each of steps of legs in response, instead of overview_polyline meant rough approximate line.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -