Where can I find the location data of a city or city to search by location?

I need to search for entries using x miles of the city function, so I have a city box with autoload attached. I am currently using the Google Geocoding API to retrieve data for outsourcer results, but we obviously cannot tune or modify this data, and it does not always come up with reasonable suggestions (even with a country). Are there any other sources of city / city location data? I tried to find out if export from OpenStreetMap or something like that is available, but I can only find map fragments or vector map data, not POI data for city and city names.

Any suggestions appreciated. Thanks.

+4
source share
3 answers

Geonames.org has a downloadable list of cities and even postal codes for many countries around the world, as well as their corresponding lat / lon point. It is licensed under Creative Commons Attribution 3.0, which means that you can use it for commercial purposes, but you must give attribution, by the way.

Although a downloadable list may mean more work at your end in terms of implementing all aspects of the search algorithm, the silver lining is that you do not get involved with the uptime / availability of a third-party network service.

The only other missing part is the schedule calculation formula. You can use the formula for the distance formula of a larger circle to calculate the distance.

I have done this myself several times. The first time you write code, it takes a little to wrap everything around you, but as soon as you make it a piece of cake after that.

Perhaps I should mention that I am the founder of SmartyStreets . We carry out street address verification and not only can we tell you if the address is good or not (which helps in a significant number of ways), but we can also provide you with the lat / lon coordinate for the given address, which can then connect to the above solution so that determine proximity to nearby places.

+5
source

I would say that you have two more options for obtaining the required functionality.

First, you can use kludge to focus results on more meaningful ones (although I would not highly recommend this method, which may be sufficient for your needs.)

Before you begin your initial request for the Google Geocoding API to get data for startup results, first determine the country in which the city is located. Then you can use the country string as a suffix to request geocoding.

Sort of:

var country = 'UK'; // from initial query, reverse geocode, etc. geocoder.geocode({ 'address': address + ', ' + country }, 

See the answer in this question for an example. Google geocoder returns wrong country ignoring region prompt

Secondly, the premise that you "obviously cannot configure or change this data" is erroneous. You can filter the results by country. Something like the following snippet shows how to expand the results.

  geocoder.geocode({ 'address': address }, function(results, status) { if(status == google.maps.GeocoderStatus.OK) { for(var i = 0, l = results.length; i < l; i++) { for (var j = 0, l2 = results[i].address_components.length; j < l2; j++) { for (var k = 0, l3 = results[i].address_components[j].types.length; k < l3; k++) { if(results[i].address_components[j].types[k]=="country") { var country = results[i].address_components[j].long_name; // do stuff based on the country // add the result to your auto-suggest, etc... } } } } }); } 

Finally, if you have implemented a CGI wrapper for geocoding, you can cache the results. Thus, your application will automatically create your database for you. This will save the actual execution of geocoding in general for known results. I think this is almost what you are hinting at in your question, and there are no reasons why you could not pre-populate your cache with known results if you could find a reliable data source.

Take a look at this document, which describes various geocoding strategies using Api maps - it discusses things like caching, etc. https://developers.google.com/maps/articles/geocodestrat

EDIT

You can use something like geoPlugin

http://www.geoplugin.com/webservices/php#php_class

Take a look at the functions of nearby places, this does exactly what you want.

http://www.geoplugin.com/webservices/extras

+2
source

Check out http://geohash.org/ , this site works with many api that you might want to use. See also the article on the history of this site.

0
source

Source: https://habr.com/ru/post/1399373/


All Articles