【发布时间】:2017-07-05 11:33:53
【问题描述】:
我正在研究谷歌地图集成我正在尝试显示谷歌导航目前我正在使用以下代码。我正在尝试根据我通过 api 的位置显示像谷歌导航一样
NSURL *url=[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&alternateroutes=false&sensor=true" ,12.920631,77.670494,8.3075,77.2218]];
NSURLResponse *res;
NSError *err;NSURL *url=[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&alternateroutes=false&sensor=true" ,12.920631,77.670494,8.3075,77.2218]];
NSURLResponse *res;
NSError *err;
NSData *data=[NSURLConnection sendSynchronousRequest:[[NSURLRequest alloc] initWithURL:url] returningResponse:&res error:&err];
if(data)
{
NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if(dic)
{
NSArray *routes=dic[@"routes"];
NSArray *legs=routes[0][@"legs"];
NSArray *steps=legs[0][@"steps"];
NSLog(@"the legs are:%@",steps);
NSMutableArray *textsteps=[[NSMutableArray alloc] init];
NSMutableArray *latlong=[[NSMutableArray alloc]init];
for(int i=0; i< [steps count]; i++){
NSString *html=steps[i][@"html_instructions"];
[latlong addObject:steps[i][@"end_location"]];
NSLog(@"the data:%@",steps[i][@"end_location"]);
[textsteps addObject:html];
encodedPath = [[[steps objectAtIndex:i] valueForKey:@"polyline"] valueForKey:@"points"];
[self polylineWithEncodedString:encodedPath];
polyline.strokeColor = [UIColor redColor];
polyline.strokeWidth = 2.f;
polyline.map = mapView;
NSLog(@"the encoded patg:%@",encodedPath);
GMSMarker *marker1 = [[GMSMarker alloc]init];
marker1.map = mapView;
NSLog(@"Direction path");
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"Connection Error" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"", nil];
[alert show];
}
【问题讨论】:
-
这不是问题。你有什么问题? “我该怎么做”在这里太宽泛了。
标签: ios objective-c google-maps cocoa-touch