如何从许多相似的名称中标准化城市名称

如何从许多相似的名称中标准化城市名称

本文介绍了如何从许多相似的名称中标准化城市名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从第三方API获取城市名称.该API不返回标准化的城市名称.例如,有时是San Francisco,有时是San Francisco, CA,有时是San Francisco, USA.我不需要街道地址等.我只需要将城市名称归一化即可.我正在寻找可以帮助我满足此要求的服务.

I'm getting city name from a 3rd party API. That API doesn't return normalized city name. For example, sometimes its San Francisco, sometime its San Francisco, CA, sometimes its San Francisco, USA. I dont need street address etc.. I just need to normalize the city name to be something uniform. I'm looking for a service that could help me with this requirement.

P.S:它不是移动应用程序,它的Web应用程序和位置都不来自浏览器.

P.S: Its not mobile app, its web app and the location doesn't come from the browser.

推荐答案

您可以使用Google Maps API获取规范化的地址:

You can use the Google Maps API to get normalized address:

1)从以下位置获取结果: https://maps.googleapis .com/maps/api/geocode/json?address = san_francisco

1) Get result from: https://maps.googleapis.com/maps/api/geocode/json?address=san_francisco

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "San Francisco",
               "short_name" : "SF",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Condado San Francisco",
               "short_name" : "Condado San Francisco",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Estados Unidos",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "San Francisco, California, EE. UU.",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 37.9298239,
                  "lng" : -122.28178
               },
               "southwest" : {
                  "lat" : 37.6398299,
                  "lng" : -123.173825
               }
            },
            "location" : {
               "lat" : 37.7749295,
               "lng" : -122.4194155
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.812,
                  "lng" : -122.3482
               },
               "southwest" : {
                  "lat" : 37.70339999999999,
                  "lng" : -122.527
               }
            }
         },
         "place_id" : "ChIJIQBpAG2ahYAR_6128GcTUEo",
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

2)从$data['results'][0]['address_components'][0]['long_name']中提取城市名称.

2) Extract the city name from $data['results'][0]['address_components'][0]['long_name'].

来源: https://developers.google.com/maps/documentation/geocoding /intro

这篇关于如何从许多相似的名称中标准化城市名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:49