【发布时间】:2016-04-12 17:44:46
【问题描述】:
我试图显示两个位置之间的路径,但它不准确。
if(center.latitude != 0 && center.longitude != 0)
{
NSString *urlString = [NSString stringWithFormat:
@"%@?origin=%f,%f&destination=%f,%f&sensor=true&key=%@",
@"https://maps.googleapis.com/maps/api/directions/json",
center.latitude,
center.longitude,
center1.latitude,
center1.longitude,
KGoogleMapServerKey];
NSError *error;
NSDictionary *json =[NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString] options:NSDataReadingUncached error:&error] options:NSJSONReadingMutableContainers error:&error];
if(json[@"routes"] != nil && [json[@"routes"] count] > 0)
{
GMSPath *path =[GMSPath pathFromEncodedPath:json[@"routes"][0][@"overview_polyline"][@"points"]];
GMSPolyline *singleLine = [GMSPolyline polylineWithPath:path];
singleLine.strokeWidth = 7;
singleLine.strokeColor = [UIColor colorWithRed:56.0/255.0 green:163.0/255.0 blue:249.0/255.0 alpha:1.0];
singleLine.map = mapViewGoogle;
}
这是我得到的路径:
如您所见,蓝线(路径)并未到达目的地。
如何解决这个问题?
【问题讨论】:
-
我认为谷歌不知道如何到达目的地,因为没有路线,或者在私人区域,诸如此类。
标签: ios google-maps