How do I find country names from city names in Java?

I want to get the country name of Twitter users

To this end, from < location >, some users wrote the label of their country's name, some wrote the name of their city, and some wrote the name of their country

I want to get the country names of all users What shall I do?

Solution

One way is to use the Google Maps API (although it may be excessive) For example, suppose someone lists their country as "Jakarta" (actually a city in Indonesia) You will then submit the following Maps API requests:

http://maps.googleapis.com/maps/api/geocode/json?address=Jakarta&sensor=false

It returns a JSON object Then, use your favorite JSON parser to parse and extract the "long_name" field of the "address component" field, with the type of "country" In this case, it is "Indonesia"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>