【发布时间】:2017-01-23 19:04:01
【问题描述】:
如何在两个未连接道路的目的地之间绘制自定义路线?
例如,如果 Source 是 The Pizza Factory,Destination 是 ATI Solutions,我必须像这样绘制路线,但没有道路可以连接这两个地方.
我尝试了 Google 的折线代码,但它只提供道路上的航点。
NSString *urlString = [NSString stringWithFormat:@"%@?origin=%@,%@&destination=%f,%f&sensor=false&waypoints=optimize:true&mode=driving", @"https://maps.googleapis.com/maps/api/directions/json", getmycurrlat, getmycurrlong, LATI, LONGI];
NSLog(@"my driving api URL --- %@", urlString);
NSLog(@"you clicked on button %ld", (long)sender.tag);
NSURL* url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@", urlString]];
NSURLResponse* res;
NSError* err;
NSData* data = [NSURLConnection sendSynchronousRequest:[[NSURLRequest alloc] initWithURL:url] returningResponse:&res error:&err];
if (data == nil) {
return;
}
NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSDictionary* routes = [dic objectForKey:@"routes"][0];
NSDictionary* route = [routes objectForKey:@"overview_polyline"];
NSString* overview_route = [route objectForKey:@"points"];
GMSPath* path = [GMSPath pathFromEncodedPath:overview_route];
GMSPolyline* polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 5.f;
polyline.map = self.mapView;
感谢所有帮助!
【问题讨论】:
-
地图首选的标准路线制作路线是在有适当空间的道路上通过,您想制作什么样的自定义路线?
-
比萨工厂和ATI解决方案之间没有道路连接,只有两座建筑物之间有一个空间。有没有办法像在快照中一样画线?
-
如果您事先提供静态
latlong,我的 exp 地图中只会在连接的道路上创建路线,但也有动态方式在移动 have a look 时创建路线投注源到 dest。 -
有没有办法创建自定义航点?
-
你有什么运气吗?
标签: ios objective-c google-maps