日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS第三方地图-百度地图定位的封装

發布時間:2025/3/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS第三方地图-百度地图定位的封装 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// // BaiduMapTools.h // baidumapTest // // Created by apple on 15/8/26. // Copyright (c) 2015年 tqh. All rights reserved. // #import <Foundation/Foundation.h>@interface WJBaiduMapTools : NSObject /**單例*/ +(WJBaiduMapTools *)instance;/**定位,能得到省市街道*/ - (void)startlocation:(BOOL)needaddresslocationSuccess:(void(^)(double longitude,double latitude)) locationSuccessaddressSuccess:(void(^)(double longitude,double latitude,BMKAddressComponent *address))addressSuccess;/**停止定位*/ - (void)stoplocation; @end // // BaiduMapTools.m // baidumapTest // // Created by apple on 15/8/26. // Copyright (c) 2015年 tqh. All rights reserved. // #import "WJBaiduMapTools.h" //注:需要導入百度地圖api@interface WJBaiduMapTools ()<BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate> {BMKLocationService *_locService; //定位BMKGeoCodeSearch *_searcher; //geo搜索服務BOOL _needaddress; //是否定位//得到經緯度void (^ _locationSuccess)(double longitude,double latitude);//得到經緯度和地理位置信息void (^ _addressSuccess)(double longitude,double latitude,BMKAddressComponent *address); }@end@implementation WJBaiduMapTools+(WJBaiduMapTools *)instance {static WJBaiduMapTools *location;@synchronized(self) {if(!location) {location = [[WJBaiduMapTools alloc] init];}}return location; }- (instancetype)init {self = [super init];if (self) {_needaddress=NO;[BMKLocationService setLocationDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];[BMKLocationService setLocationDistanceFilter:100.f];_locService = [[BMKLocationService alloc]init];_locService.delegate = self;_searcher =[[BMKGeoCodeSearch alloc]init];_searcher.delegate = self;}return self; }//開始定位 -(void)startlocation:(BOOL)needaddress locationSuccess:(void (^)(double, double))locationSuccess addressSuccess:(void (^)(double, double, BMKAddressComponent *))addressSuccess{_needaddress=needaddress;_locationSuccess=locationSuccess;_addressSuccess=addressSuccess;if (_locService!=nil) {[_locService startUserLocationService];} }//停止定位 - (void)stoplocation {if (_locService!=nil) {[_locService stopUserLocationService];} }// 定位成功 -(void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{[_locService stopUserLocationService];double longitude=userLocation.location.coordinate.longitude;double latitude=userLocation.location.coordinate.latitude;if (_locationSuccess) {_locationSuccess(longitude,latitude);}if (_needaddress) {//發起反向地理編碼檢索BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];reverseGeocodeSearchOption.reverseGeoPoint = (CLLocationCoordinate2D){latitude,longitude};BOOL flag = [_searcher reverseGeoCode:reverseGeocodeSearchOption];if(flag){NSLog(@"反geo檢索發送成功");}else{NSLog(@"反geo檢索發送失敗"); }}else{} }-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{if (error == BMK_SEARCH_NO_ERROR) {if (_addressSuccess) {_addressSuccess(result.location.longitude,result.location.latitude,result.addressDetail);}} } @end

?

轉載于:https://www.cnblogs.com/hxwj/p/4761099.html

總結

以上是生活随笔為你收集整理的iOS第三方地图-百度地图定位的封装的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。