高德地图 正向地理编码 逆向地理编码
2016-07-06 09:23
435 查看
设置检索KEY的方法 : [AMapSearchServices sharedServices].apiKey
= apiKey;
-------------------------------------------------------------------------------------------------------
#pragma mark -- 正向地理编码 (根据地名定位当前位置)
Address 用户当前位置:
- (void)getDefaultUserLocationWithAddress:(NSString *)address {
self.searchAPI = [[AMapSearchAPI alloc] init];
self.searchAPI.delegate = self;
//构造AMapGeocodeSearchRequest对象,address为必选项,city为可选项
AMapGeocodeSearchRequest *searchRequest = [[AMapGeocodeSearchRequest alloc] init];
searchRequest.address = address;
//发起正向地理编码
[self.searchAPI AMapGeocodeSearch: searchRequest];
}
- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response
{
if (response.geocodes.count == 0) {
return;
}
NSArray *locationInfo = response.geocodes; // 用户位置信息
AMapGeocode *geocode = locationInfo.firstObject;
AMapGeoPoint *geoPoint = geocode.location;
CLLocationCoordinate2D Coordinate2D = CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude); // 根据地址获取的经纬度
[self.mapView setCenterCoordinate:Coordinate2D animated:YES];// 在地图上设置出该位置
NSString *geocodeString = [NSString stringWithFormat:@"经纬度:%f,%f", geoPoint.latitude, geoPoint.longitude];
}*/
#pragma mark -- 逆向地理编码 (根据经纬度获取地名)
// latitude longtitud 传入经纬度
- (void)getNameByLatitude:(CLLocationDegrees)latitude andLongTitude:(CLLocationDegrees)longtitud
{
self.searchAPI = [[AMapSearchAPIalloc]init];
self.searchAPI.delegate =self;
AMapReGeocodeSearchRequest *regeoRequest = [[AMapReGeocodeSearchRequestalloc]init];
regeoRequest.location = [AMapGeoPointlocationWithLatitude:latitudelongitude:longtitud];
regeoRequest.radius =2000;
regeoRequest.requireExtension =YES;
[self.searchAPIAMapReGoecodeSearch: regeoRequest];
// 发起检索
}
- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse
*)response
{
if (![DDUtilsisNullOrNil:response.regeocode])
{
AMapReGeocode *regeocode = response.regeocode;
CLLocationDegrees latitude = request.location.latitude;
CLLocationDegrees longitude = request.location.longitude;
NSString *address = regeocode.formattedAddress; // 获得检索位置
}
}
= apiKey;
-------------------------------------------------------------------------------------------------------
#pragma mark -- 正向地理编码 (根据地名定位当前位置)
Address 用户当前位置:
- (void)getDefaultUserLocationWithAddress:(NSString *)address {
self.searchAPI = [[AMapSearchAPI alloc] init];
self.searchAPI.delegate = self;
//构造AMapGeocodeSearchRequest对象,address为必选项,city为可选项
AMapGeocodeSearchRequest *searchRequest = [[AMapGeocodeSearchRequest alloc] init];
searchRequest.address = address;
//发起正向地理编码
[self.searchAPI AMapGeocodeSearch: searchRequest];
}
- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response
{
if (response.geocodes.count == 0) {
return;
}
NSArray *locationInfo = response.geocodes; // 用户位置信息
AMapGeocode *geocode = locationInfo.firstObject;
AMapGeoPoint *geoPoint = geocode.location;
CLLocationCoordinate2D Coordinate2D = CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude); // 根据地址获取的经纬度
[self.mapView setCenterCoordinate:Coordinate2D animated:YES];// 在地图上设置出该位置
NSString *geocodeString = [NSString stringWithFormat:@"经纬度:%f,%f", geoPoint.latitude, geoPoint.longitude];
}*/
#pragma mark -- 逆向地理编码 (根据经纬度获取地名)
// latitude longtitud 传入经纬度
- (void)getNameByLatitude:(CLLocationDegrees)latitude andLongTitude:(CLLocationDegrees)longtitud
{
self.searchAPI = [[AMapSearchAPIalloc]init];
self.searchAPI.delegate =self;
AMapReGeocodeSearchRequest *regeoRequest = [[AMapReGeocodeSearchRequestalloc]init];
regeoRequest.location = [AMapGeoPointlocationWithLatitude:latitudelongitude:longtitud];
regeoRequest.radius =2000;
regeoRequest.requireExtension =YES;
[self.searchAPIAMapReGoecodeSearch: regeoRequest];
// 发起检索
}
- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse
*)response
{
if (![DDUtilsisNullOrNil:response.regeocode])
{
AMapReGeocode *regeocode = response.regeocode;
CLLocationDegrees latitude = request.location.latitude;
CLLocationDegrees longitude = request.location.longitude;
NSString *address = regeocode.formattedAddress; // 获得检索位置
}
}
相关文章推荐
- mysql5.7 二进制包安装
- String与string的区别
- 李洪强经典面试题23
- 浅谈一类积性函数的前缀和
- IOS实现选择城市后跳转Tabbar效果
- DeepID算法实践
- poj 3083 dfs+bfs最短路
- HelloCharts的折线图跟json数据交互
- html css控制浮动元素居中显示
- 系统短信
- 开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
- c#中const与readonly区别
- 【代码笔记】iOS-获得徐家汇的天气预报
- “爱运动管理系统”诞生记(11)
- 腾讯2017暑期实习生编程题(3道)
- window下使用IIS搭建ftp服务器
- kafka2.9.2的伪分布式集群安装和demo(java api)测试
- errno.h
- ReLU上的花样
- C++、Java、JavaScript中的正则表达式