简体   繁体   English

如何在HERE MAP iOS上从经纬度获取完整地址

[英]How to get full address from latitude and longitude on HERE MAP iOS

I want to fetch full address by latitude and longitude in here map iOS premium sdk.In Android, I see there is the option to fetch address by latitude and longitude with ReverseGeocodeRequest but I did not find anything for iOS. 我想在此处的地图iOS高级sdk中按纬度和经度获取完整的地址。在Android中,我看到可以使用ReverseGeocodeRequest按纬度和经度获取地址,但我没有为iOS找到任何东西。

Currently, I am fetching the address from CLLocationCoordinate2D but I think it will be better if I will fetch it by HERE MAP sdk because I am using HERE MAP not Apple MAP. 目前,我正在从CLLocationCoordinate2D获取地址,但是我认为如果通过HERE MAP SDK来获取地址会更好,因为我使用的是HERE MAP,而不是Apple MAP。 I have attached the android code below. 我已经附上了下面的android代码。

GeoCoordinate vancouver = new GeoCoordinate(latitude,longitude);

        new ReverseGeocodeRequest(vancouver).execute(new ResultListener<Location>() {

            @Override

            public void onCompleted(Location location, ErrorCode errorCode) {

                try {

                    assetData.address = location.getAddress().toString().replace("\n", "");



                } catch (NullPointerException e) {

                    e.printStackTrace();

                }



            }

        });

You have to make use of NMAAddress class in the HERE iOS SDK. 您必须在HERE iOS SDK中使用NMAAddress类。

NMAAddress provides textual address information including house number, street name, city, country, district and more. NMAAddress提供文本地址信息,包括门牌号,街道名称,城市,国家/地区等。 It encompasses everything about an address or a point on the map. 它涵盖了有关地址或地图上某个点的所有内容。 The NMAPlaceLocation class represents an area on the map where additional attributes can be retrieved. NMAPlaceLocation类表示地图上可以检索其他属性的区域。 These additional attributes include NMAAddress, unique identifier, label, location, access locations, and NMAGeoBoundingBox for the location 这些其他属性包括NMAAddress,唯一标识符,标签,位置,访问位置以及该位置的NMAGeoBoundingBox

Please check the document section Geocoding and Reverse Geocoding for more details including sample codes. 请检查文档地理编码和反向地理编码部分以获取更多详细信息,包括示例代码。

You need to use Google API to fetch address from Geo Coordinates, for that please use following code 您需要使用Google API从地理坐标中获取地址,为此请使用以下代码

func getAddressFromLatLong(latitude: Double, longitude : Double) {
    let url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=\(latitude),\(longitude)&key=YOUR_API_KEY_HERE"

    Alamofire.request(url).validate().responseJSON { response in
        switch response.result {
        case .success:

            let responseJson = response.result.value! as! NSDictionary

            if let results = responseJson.object(forKey: "results")! as? [NSDictionary] {
                if results.count > 0 {
                    if let addressComponents = results[0]["address_components"]! as? [NSDictionary] {
                        self.address = results[0]["formatted_address"] as? String
                        for component in addressComponents {
                            if let temp = component.object(forKey: "types") as? [String] {
                                if (temp[0] == "postal_code") {
                                    self.pincode = component["long_name"] as? String
                                }
                                if (temp[0] == "locality") {
                                    self.city = component["long_name"] as? String
                                }
                                if (temp[0] == "administrative_area_level_1") {
                                    self.state = component["long_name"] as? String
                                }
                                if (temp[0] == "country") {
                                    self.country = component["long_name"] as? String
                                }
                            }
                        }
                    }
                }
            }
        case .failure(let error):
            print(error)
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM