這是我踩了一個坑照激,注意咯发魄,注意咯
根據(jù)已知的經(jīng)度值(longitude)和緯度值(latitude),拼接可定位的高德地圖鏈接:
http://ditu.amap.com/regeo 是高德過時的api俩垃,不要去再用了励幼,安心走高德地圖Sdk,獲取短鏈URL
iOS高德只需要引入兩個庫
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
mLocationUrl = "http://ditu.amap.com/regeo?lng="+longitude+"&lat="+latitude;
示例:longitude=104.06074583530426 口柳, latitude=30.5379691198173則:
mLocationUrl = "http://ditu.amap.com/regeo?lng="+longitude+"&lat="+latitude;
得到:
mLocationUrl = "http://ditu.amap.com/regeo?lng=104.06074583530426&lat=30.5379691198173";
下面是IOS端的短鏈獲取代碼苹粟,可以直接拿去使用
#import "AMapManager.h"
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
@interface AMapManager()<AMapSearchDelegate>
@property (nonatomic,strong)NSMutableArray *searchRequestArray;
@property (nonatomic,strong)AMapSearchAPI *searchApi;
@property (nonatomic,copy)ShareLoctionUrlBlock shareUrlLocationBlaock;
@end
@implementation AMapManager
+ (instancetype)shareInstance {
static AMapManager *share;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
share = [[AMapManager alloc] init];
});
return share;
}
- (void)amapLocationShareSearchWithlat:(double)lat lon:(double)lon complete:(ShareLoctionUrlBlock)complete {
self.shareUrlLocationBlaock = complete;
AMapLocationShareSearchRequest *request = [[AMapLocationShareSearchRequest alloc] init];
request.location = [AMapGeoPoint locationWithLatitude:lat longitude:lon];
[self.searchApi AMapLocationShareSearch:request];
}
// 當請求發(fā)生錯誤時,會調(diào)用代理的此方法.
- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error {
if (self.shareUrlLocationBlaock) {
self.shareUrlLocationBlaock(nil, error);
self.shareUrlLocationBlaock = nil;
}
}
// POI查詢回調(diào)函數(shù)
- (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response {
}
// 短串分享搜索回調(diào)
- (void)onShareSearchDone:(AMapShareSearchBaseRequest *)request response:(AMapShareSearchResponse *)response {
if (self.shareUrlLocationBlaock) {
self.shareUrlLocationBlaock(response.shareURL, nil);
self.shareUrlLocationBlaock = nil;
}
}
- (AMapSearchAPI *)searchApi {
if (!_searchApi) {
_searchApi = [[AMapSearchAPI alloc] init];
_searchApi.delegate = self;
}
return _searchApi;
}
- (NSMutableArray *)searchRequestArray {
if (!_searchRequestArray) {
_searchRequestArray = [NSMutableArray array];
}
return _searchRequestArray;
}
@end