不需要显示地图 就获得用户当前经纬度 超简单的方法

来源:互联网 发布:java 书籍推荐 编辑:程序博客网 时间:2024/06/05 11:48

1.遵循协议

CLLocationManagerDelegate,AMapSearchDelegate,AMapLocationManagerDelegate


2. API

MAMapServices.sharedServices().apiKey =APIKey

        

        AMapLocationServices.sharedServices().apiKey = APIKey

        

        AMapSearchServices.sharedServices().apiKey = APIKey

        

        AMapNaviServices.sharedServices().apiKey = APIKey

        

        search =AMapSearchAPI()

        

        search?.delegate =self

        

        mapLacationManager.delegate =self



3.方法

//MARK:_调用获取用户地理位置信息

    func getMapData() {

        

        mapLacationManager =AMapLocationManager()

        

        mapLacationManager.allowsBackgroundLocationUpdates =true

        

        mapLacationManager.requestLocationWithReGeocode(true) { (location, regecode, error) in

            

            print(location)

            

            if (location !=nil) {

                

                self.LONGITUDES = location.coordinate.longitude

                

                self.LATITUDES = location.coordinate.latitude

                

                print("self.LONGITUDES:\(self.LONGITUDES)")

                

                print("self.LATITUDES:\(self.LATITUDES)")

                

                

                

            } else {

                

                print(error)

                

            }

            


        }

        

        

    }


4。最后切记 调用哦

    





0 0