gpt4 book ai didi

iphone - 带地址的 MKMapView

转载 作者:行者123 更新时间:2023-12-03 18:25:36 27 4
gpt4 key购买 nike

有没有办法让 MKMapView 放置一个具有给定地址的图钉?不使用坐标

谢谢

最佳答案

这是我在应用程序中使用的代码片段

-(CLLocationCoordinate2D) getLocationFromAddressString:(NSString*) addressStr {
NSString *urlStr = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[addressStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr]];
NSArray *items = [locationStr componentsSeparatedByString:@","];

double lat = 0.0;
double lon = 0.0;

if([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:@"200"]) {
lat = [[items objectAtIndex:2] doubleValue];
lon = [[items objectAtIndex:3] doubleValue];
}
else {
NSLog(@"Address, %@ not found: Error %@",addressStr, [items objectAtIndex:0]);
}
CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = lon;

return location;
}

关于iphone - 带地址的 MKMapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3383250/

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