在我的应用程序中,我打算使用前向GeoCoding来允许用户在搜索栏中输入地址,然后在 map 上放置标记。
我可以仔细检查以下方法是否适用于我打算做什么?
-(CLLocationCoordinate2D) addressLocation {
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[searchBar.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSError* error;
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
我将调用上述方法来获取经度和纬度,然后在 map 上相应地添加注释。我是否需要为此注册APIKey?如果是,我应该在哪里添加它?在这种情况下,我仍可以对我的应用收取费用吗?
谢谢!
真和
最佳答案
虽然api中包含反向地理编码,但不包含常规地理编码,并且需要获得Google的许可。可悲的是,我可以告诉你这也不便宜,每年大约8000英镑以上,具体取决于销量。
另一种方法是使用免费的地理编码服务,只需在Google上搜索它,您就会发现一些。另外,其他 map 服务提供商(例如CloudMade)也可以执行类似的操作,而费用却只是其中的一小部分。
关于objective-c - objective-c :如果我使用前向GeoCoding(Google API),可以为我的应用程序收取费用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5932461/