iPhone上的地图上的路径线绘制
问题描述:
我正在尝试两个location.it之间的地图上的绘制路径线,它不是在道路上显示它就像道路上两个地方标记之间的最短距离。iPhone上的地图上的路径线绘制
我已经尝试过在路上对齐。 我MKDirectionsRequest
以及(这是给错误,我搜索,然后显示这是不是在印度工作的一些地方。)
任何其他方式来绘制道路线。
答
苹果的卫星,导航,导航服务没有出现在几个国家这就是为什么你没有得到适当的结果。
请从苹果检查此链接:http://www.apple.com/in/ios/feature-availability/
不如你用谷歌地图在您的应用程序,让您的位置坐标。
https://developers.google.com/maps/documentation/ios-sdk/start此链接将有助于您
+1
这个问题被标记为谷歌地图。 –
答
您可以使用googleMAP API进行此操作。
- (void)drawRoute :(CLLocationCoordinate2D)myOrigin destination:(CLLocationCoordinate2D)myDestination
{
[self fetchPolylineWithOrigin:myOrigin destination:myDestination completionHandler:^(GMSPolyline *polyline1)
{
if(polyline1)
polyline1.map = mapView_;
}];
}
- (void)fetchPolylineWithOrigin:(CLLocationCoordinate2D)origin destination:(CLLocationCoordinate2D)destination completionHandler:(void (^)(GMSPolyline *))completionHandler
{
NSString *originString = [NSString stringWithFormat:@"%f,%f", origin.latitude, origin.longitude];
NSString *destinationString = [NSString stringWithFormat:@"%f,%f", destination.latitude, destination.longitude];
NSString *directionsAPI = @"https://maps.googleapis.com/maps/api/directions/json?";
NSString *directionsUrlString = [NSString stringWithFormat:@"%@&origin=%@&destination=%@&mode=driving", directionsAPI, originString, destinationString];
NSURL *directionsUrl = [NSURL URLWithString:directionsUrlString];
NSURLSessionDataTask *fetchDirectionsTask = [[NSURLSession sharedSession] dataTaskWithURL:directionsUrl completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if(error)
{
if(completionHandler)
completionHandler(nil);
return;
}
NSArray *routesArray = [json objectForKey:@"routes"];
GMSPolyline *polyline = nil;
if ([routesArray count] > 0)
{
NSDictionary *routeDict = [routesArray objectAtIndex:0];
NSDictionary *routeOverviewPolyline = [routeDict objectForKey:@"overview_polyline"];
NSString *points = [routeOverviewPolyline objectForKey:@"points"];
GMSPath *path = [GMSPath pathFromEncodedPath:points];
polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeColor = [UIColor redColor];
polyline.strokeWidth = 5.0;
}
if(completionHandler)
completionHandler(polyline);
});
}];
[fetchDirectionsTask resume];
}
你能告诉我你做了什么?我的意思是代码? –
你使用的是谷歌地图吗? –
http://*.com/questions/10598322/iphone-how-to-draw-line-between-two-points-on-mapkit –