Retrieve city names and locations. Find cities within N miles.
US cities. Latitude and longitude values are in decimal format. The proximity API is up to 50 miles. For API integration, implement client side failover for high availability - a JavaScript example is shown below. Freely utilize this PixelTwenty service in applications and services of your own.


Cities By Name


GET [service]/cities/byname?starts-with=[three letters or more]
GET https://latlng-a.pixeltwenty.com/cities/byname?starts-with=sal (for example)

https://latlng-a.pixeltwenty.com/cities/byname?starts-with=




Cities By Proximity


GET [service]/cities/within?miles=[miles]&lat=[decimal latitude]&lng=[decimal longitude]
GET https://latlng-a.pixeltwenty.com/cities/within?miles=50&lat=40.7774&lng=-111.93 (for example)

https://latlng-a.pixeltwenty.com/cities/within?miles= &lat= &lng=




Services and Failover


The service locations are https://latlng-a.pixeltwenty.com and https://latlng-b.pixeltwenty.com. Implement client side failover for high availability. For example, in JavaScript: var serviceIndex = 0; var P20CallWithFailover = function(endpoint, callback) { var services = [ "https://latlng-a.pixeltwenty.com", "https://latlng-b.pixeltwenty.com" ]; var busy = false; makeCall(0); function makeCall(tries) { if (busy) return; busy = true; var xhr = new XMLHttpRequest(); xhr.responseType = "text"; xhr.onreadystatechange = function() { if (xhr.readyState == 4) { busy = false; if (xhr.status == 200) { callback && callback(xhr.responseText); } else { tries++; if (tries < services.length+1) { serviceIndex = (serviceIndex + 1) % services.length; makeCall(tries); } else { callback && callback(JSON.stringify([])); } } } } var service = services[serviceIndex]; xhr.open("GET", service + endpoint, true); xhr.timeout = 4000; xhr.send(); } }; And use like this for example: P20CallWithFailover("/cities/byname?starts-with=" + encodeURIComponent("3LettersOrMore"), callback); function callback(data) { // do something with the JSON format data }
Viewing this page:
This service utilizes data compiled by simplemaps

© 2020 PixelTwenty LLC
info@pixeltwenty.com