gpt4 book ai didi

iphone - 在 iphone 的谷歌地图上绘制路线

转载 作者:行者123 更新时间:2023-12-01 18:30:02 26 4
gpt4 key购买 nike

我想使用纬度和经度在 map View 上绘制路线。怎么可能画画?

这是我的代码。但它不工作。我在点可变数组中添加了位置。然后调用 drawRoute 函数在该位置之间绘制路线。

- (void)viewDidLoad {
[super viewDidLoad];
CLLocationCoordinate2D location;
location.latitude = (double) 23.00000;
location.longitude = (double) 73.00000;


CLLocationCoordinate2D location2;
location2.latitude = (double) 73.00000;
location2.longitude = (double) 23.00000;

CLLocation *locationPoint1 = [[CLLocation alloc]initWithLatitude:location.latitude longitude:location.longitude];
CLLocation *locationPoint2 = [[CLLocation alloc]initWithLatitude:location2.latitude longitude:location2.longitude];
[self.points addObject:locationPoint1];
[self.points addObject:locationPoint2];
[self performSelector:@selector(drowRoute)];
}


-(void)drowRoute{
CGContextRef context = UIGraphicsGetCurrentContext();
// CGContextSetStrokeColorWithColor(context, [[UIColor blueColor]CGColor]);
CGContextSetLineWidth(context, 2.0);

for(int idx = 0; idx < self.points.count; idx++)
{
CLLocation* location = [self.points objectAtIndex:idx];
CGPoint point = [mapView convertCoordinate:location.coordinate toPointToView:self.view];

if(idx == 0)
{
// move to the first point
CGContextMoveToPoint(context, point.x, point.y);
}
else
{
CGContextAddLineToPoint(context, point.x, point.y);
}
}
CGContextStrokePath(context);
}

最佳答案

我使用 Goggle map 服务使用它。您只需将经度和纬度作为参数传递给 URL休息由谷歌地图负责。

- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];

NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",c_lat,c_long,lat,lat];
//saddr= we pass source address long, lat.
//daddr= we pass destination address long, lat.

//--------use this if you have current long,lat and destination's address or street name etc...

NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",
currentLocation.latitude, currentLocation.longitude,
[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//------------------------------------------------------------------------------
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:url]]; // this line will open Google map on Maps application on device and in Safari in Simulator.


}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

curntloc = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];

NSLog(@"in func--> %f %f",curntloc.coordinate.latitude, curntloc.coordinate.longitude);
}

关于iphone - 在 iphone 的谷歌地图上绘制路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10119235/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com