ios 持续获取定位 高德地图_概述-iOS 定位SDK | 高德地图API
簡介
高德 iOS 定位 SDK 提供了不依賴于地圖定位的定位功能,開發者可以無地圖顯示的場景中便捷地為應用程序添加定位功能。
iOS定位SDK提供了單次定位、連續定位、逆地理信息、地理圍欄等功能。
面向的讀者
高德地圖定位 SDK 是提供給具有一定 iOS 編程經驗,了解面向對象編程概念的讀者使用的 iOS 移動端 SDK。
功能介紹與體驗
抱歉,您的瀏覽器不支持video標簽
抱歉,您的瀏覽器不支持video標簽
抱歉,您的瀏覽器不支持video標簽基礎定位
- (void)configLocationManager
{
self.locationManager = [[AMapLocationManager alloc] init];
[self.locationManager setDelegate:self];
[self.locationManager setPausesLocationUpdatesAutomatically:NO];
[self.locationManager setAllowsBackgroundLocationUpdates:YES];
}
- (void)startSerialLocation
{
//開始定位
[self.locationManager startUpdatingLocation];
}
- (void)stopSerialLocation
{
//停止定位
[self.locationManager stopUpdatingLocation];
}
- (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error
{
//定位錯誤
NSLog(@"%s, amapLocationManager = %@, error = %@", __func__, [manager class], error);
}
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location
{
//定位結果
NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
}
逆地理編碼
- (void)configLocationManager
{
self.locationManager = [[AMapLocationManager alloc] init];
[self.locationManager setDelegate:self];
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
[self.locationManager setLocationTimeout:6];
[self.locationManager setReGeocodeTimeout:3];
}
- (void)locateAction
{
//帶逆地理的單次定位
[self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
if (error)
{
NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
if (error.code == AMapLocationErrorLocateFailed)
{
return;
}
}
//定位信息
NSLog(@"location:%@", location);
//逆地理信息
if (regeocode)
{
NSLog(@"reGeocode:%@", regeocode);
}
}];
}
地理圍欄
- (void)configLocationManager
{
self.locationManager = [[AMapLocationManager alloc] init];
[self.locationManager setDelegate:self];
[self.locationManager setPausesLocationUpdatesAutomatically:NO];
[self.locationManager setAllowsBackgroundLocationUpdates:YES];
}
- (void)addCircleReionForCoordinate:(CLLocationCoordinate2D)coordinate
{
int radius = 250;
//創建circleRegion
AMapLocationCircleRegion *cirRegion = [[AMapLocationCircleRegion alloc] initWithCenter:coordinate
radius:radius
identifier:@"circleRegion"];
//添加地理圍欄
[self.locationManager startMonitoringForRegion:cirRegion];
//保存地理圍欄
[self.regions addObject:cirRegion];
//添加Overlay
MACircle *circle = [MACircle circleWithCenterCoordinate:coordinate radius:radius];
[self.mapView addOverlay:circle];
[self.mapView setVisibleMapRect:circle.boundingMapRect];
}
- (void)amapLocationManager:(AMapLocationManager *)manager didStartMonitoringForRegion:(AMapLocationRegion *)region
{
NSLog(@"開始監聽地理圍欄:%@", region);
}
- (void)amapLocationManager:(AMapLocationManager *)manager monitoringDidFailForRegion:(AMapLocationRegion *)region withError:(NSError *)error
{
NSLog(@"監聽地理圍欄失敗:%@", error.localizedDescription);
}
- (void)amapLocationManager:(AMapLocationManager *)manager didEnterRegion:(AMapLocationRegion *)region
{
NSLog(@"進入地理圍欄:%@", region);
}
- (void)amapLocationManager:(AMapLocationManager *)manager didExitRegion:(AMapLocationRegion *)region
{
NSLog(@"退出地理圍欄:%@", region);
}
賬號與Key的申請
注冊成為高德開發者需要分三步:
第一步,注冊高德開發者;
第二步,去控制臺創建應用;
第三步,獲取Key。
具體步驟可參看下圖
兼容性
高德地圖 iOS 定位 SDK V2.2.0 之前的版本兼容 iOS 6.0 系統,從 V2.2.0 版本以后從 iOS 7.0 系統開始支持。SDK 內部網絡訪問全部應用域名訪問,不涉及 ipv4 和 ipv6 的問題。
給開發者的建議
高德開放平臺提供的地圖API/SDK,任何非盈利性網站/應用均可免費使用 。請參閱《高德地圖 API 使用條款》獲得詳細信息。
總結
以上是生活随笔為你收集整理的ios 持续获取定位 高德地图_概述-iOS 定位SDK | 高德地图API的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: arduino 嗡鸣器 音乐_[求助]怎
- 下一篇: cocos2d 屏幕適配_cocos2d