有没有IOS/iPhone示例代码,可以通过placename和/或通过使用Google Maps API的地图来选择位置?
因此,让用户通过以下两者的用户选择位置的示例:-键入位置&让Google Maps API尝试在地图上查找位置和/或-移动地图上的位置标记-例如,您可以输入一个地点并在地图上靠近,然后使用地图最终结果调整精确位置-最终结果为Lat,Long
发布于 2011-12-09 11:33:51
您所指的是正向地理编码,不幸的是,苹果还没有为它提供api。然而,还有一个最好的东西,第三方api。看看这个项目,我在两个项目中成功地使用了它,效果很好:https://github.com/bjornsallarp/BSForwardGeocoder
确保包含必要的文件,以便可以包含BSForwardGeocoder而不会出错。然后,只需在BSForwardGeocoderDelegate中创建要使用它的类,并在类中实现以下两个协议方法:
-(void)queryAddress
{
// Initialize member BSForwardGeocoder object
if (forwardGeocoder == nil) {
forwardGeocoder = [[BSForwardGeocoder alloc] initWithDelegate:self];
}
// send the request
[forwardGeocoder findLocation:@"Saint Paul, MN"];
}和:
-(void)forwardGeocoderFoundLocation:(BSForwardGeocoder *)geocoder
{
/*
* BSForwardGeocoder delegate method. Receives the callback upon geocoding data gather completion.
*/
if (forwardGeocoder.status == G_GEO_SUCCESS) {
int searchResults = [forwardGeocoder.results count];
for (int i = 0; i < searchResults; i++) {
// See the sample project code fore other useful location properties...
// Here I retrieve the returned lat and lon.
Result *location = [forwardGeocoder.results objectAtIndex:i];
mLatitude = location.latitude;
mLongitude = location.longitude;
}
} else {
NSString *message = @"";
switch (forwardGeocoder.status) {
case G_GEO_BAD_KEY:
message =@"Bad Api Key";
break;
case G_GEO_UNKNOWN_ADDRESS:
message = @"Address Not Found!";
break;
case G_GEO_TOO_MANY_QUERIES:
message = @"Too Many Queries";
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Information"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[ alert show ];
[ alert release ];
}
}这将使用sallarp提供的大型库返回明尼苏达州圣保罗的纬度和经度。
如果您想要在地图周围拖动注释并获取其坐标信息,也可以这样做,您需要将您的类设置为mkmapview委托并实现mapView:annotationView:didChangeDragState:fromOldState:方法。在您的实现中,首先检查newState是否等于mkAnnotationViewDragStateEnding,如果是,您可以通过annotationView.annotation.coordinate属性获取其坐标信息。当然,您需要将注解视图的draggable属性设置为YES。如果您愿意,您可以通过BSForwardGeocoder查询方法将这些NSString格式的坐标发送到谷歌,并获取其相关信息。
格雷格
https://stackoverflow.com/questions/8439598
复制相似问题