letsforum letsforum - 1 year ago 71
jQuery Question

Return country name from a city one?

Guys is there a way on page load grab a city name from URL and then some how return the country it belongs to?

Lets say here is my URL: site.com/sevilla_r

How can I return España on page load and show it in the page content?


If it's a country then do nothing!

Answer Source

You can use Google geocade API

Read here

For e.g. https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

This will return Country name, postal code, lat lng etc


This is how i implemented it

$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=shimla&key=';

$json = file_get_contents($url);