diff options
Diffstat (limited to 'widgets/weather/GetLatLangFromCity.php')
-rw-r--r-- | widgets/weather/GetLatLangFromCity.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/widgets/weather/GetLatLangFromCity.php b/widgets/weather/GetLatLangFromCity.php new file mode 100644 index 00000000..e05c1bc8 --- /dev/null +++ b/widgets/weather/GetLatLangFromCity.php @@ -0,0 +1,25 @@ +<?php + +$handle = fopen ("php://stdin","r"); +echo "Country (like DE for Germany): "; +$country = fgets($handle); +echo "City (like Berlin): "; +$city = fgets($handle); + +// get lat & long from google maps +$MAPSURL = "http://maps.googleapis.com/maps/api/geocode/json?address=".$city.",".$country."&sensor=false"; +$json = file_get_contents($MAPSURL); +$data = json_decode($json, true); + +if( !isset($data['results'][0]) ) { + echo "no latitude and longitude find for: ".$city.",".$country." !\n"; + exit; +} +$latitude = $data['results'][0]['geometry']['location']['lat']; +$longitude = $data['results'][0]['geometry']['location']['lng']; + +echo "latitude: ".$latitude."\n"; +echo "longitude: ".$longitude."\n"; +echo "put these values in update_weather.config\n"; + +?> |