get city name from latitude and longitude in php using geocode api

Solutions on MaxInterview for get city name from latitude and longitude in php using geocode api by the best coders in the world

showing results for - "get city name from latitude and longitude in php using geocode api"
Linus
15 Aug 2016
1var x=document.getElementById("demo");
2function getLocation(){
3    if (navigator.geolocation){
4        navigator.geolocation.getCurrentPosition(showPosition,showError);
5    }
6    else{
7        x.innerHTML="Geolocation is not supported by this browser.";
8    }
9}
10
11function showPosition(position){
12    lat=position.coords.latitude;
13    lon=position.coords.longitude;
14    displayLocation(lat,lon);
15}
16
17function showError(error){
18    switch(error.code){
19        case error.PERMISSION_DENIED:
20            x.innerHTML="User denied the request for Geolocation."
21        break;
22        case error.POSITION_UNAVAILABLE:
23            x.innerHTML="Location information is unavailable."
24        break;
25        case error.TIMEOUT:
26            x.innerHTML="The request to get user location timed out."
27        break;
28        case error.UNKNOWN_ERROR:
29            x.innerHTML="An unknown error occurred."
30        break;
31    }
32}
33
34function displayLocation(latitude,longitude){
35    var geocoder;
36    geocoder = new google.maps.Geocoder();
37    var latlng = new google.maps.LatLng(latitude, longitude);
38
39    geocoder.geocode(
40        {'latLng': latlng}, 
41        function(results, status) {
42            if (status == google.maps.GeocoderStatus.OK) {
43                if (results[0]) {
44                    var add= results[0].formatted_address ;
45                    var  value=add.split(",");
46
47                    count=value.length;
48                    country=value[count-1];
49                    state=value[count-2];
50                    city=value[count-3];
51                    x.innerHTML = "city name is: " + city;
52                }
53                else  {
54                    x.innerHTML = "address not found";
55                }
56            }
57            else {
58                x.innerHTML = "Geocoder failed due to: " + status;
59            }
60        }
61    );
62}
Domenico
16 Jan 2020
1<p><button onclick="getLocation()">Get My Location</button></p>
2<p id="demo"></p>
3<script src="http://maps.google.com/maps/api/js?key=YOUR_API_KEY"></script>
queries leading to this page
get city and country from lat long javascriptgoogle api key for getting lat long from addressgeocoder php get longitude and latitudefree api that returns lat lon from city namehow to convert city into latitude and longitude javascripthow to get lat and long from city name and state name javascriptget city and town name from latitude longitudejs how to find a city by longitude and latitudeget city longitude latitudelat long to country code api freelatitude longitude php geo apiget current latitude and longitude phphow to get complete address from latitude and longitude in phpget city name from latitude and longitude reactfree api to return lat and longapi coordinatesjavascript navigator get city from latitude longitudecities found json api javascripthow to get latitude and longitude from address in phpfetching latitude and longitude in phphow to get city name from latitude and longitude in javascripthow to get city name from latitude and longitudejavascript get city from latitude longitudeget city from coordinates jsfree lng and latitude to city apiget city name from latitude and longitude without geolocation in phpjs city to lon lat apihow to get place name from latitude and longitudehow to get city name from latitude and longitude ingeocoding apionline api get long and latidutdehow to get location name from latitude and longitude in javascriptget city from lat long javascriptget latitude from city name jshow do i check longitude and latitude using apihow to get cordinate from city name jshow to get location name from latitude and longitudeapi response to show lat long for multiple locationshow to get city name from latitude longitudejs coordinates to citytranslate city name to latlngwhen invoked 2c this function should use geocode xyz 27s api retrieve the city data 2c which uses a url formatted as follows 3a https 3a 2f 2fgeocode xyz 2fseattle 3fjson 3d1api to find latitude and longitude using city nam 2cefrom city to coordinate jshow to get city from latitude and longitudeapi get city from lat longget city state country from lat long javascriptget city name from latitude and longitude javascriptget city name from latitude and longitude jsget city name from latitude and longitude in php using geocode apigeocode from cityget city from latitude longitudeget city by longitude and latitude google maps apihow to turn lat and long into city javascriptfree get boundaries coordinate apiget city name by latitude and longitudehow to get location name from latitude and longitude in angularget city name based on lat and logitudeusing the geocode apiget city from coordinates angularget city name from latitude and longitude in jsconvert from lat and lon to city kotlingeoreference google apiget city using longitude and latitude apigegt city name from google map using angularapi latitude and longitude of city by namegoogle map get city name by latitude and longitudeget lat and long from city name javascriptget place name from latitude and longitude google mapshow to get city name using google api in reactgoogle api to get latitude and longitude from city idget city name from latitude and longitude in phpget longitude and latitude from city name jsapps script map get city name from coordinatesgoogle api get lat long from addresscity name from latitude and longitudeget city name by lat longget place name from latitude and longitudehow to get the latitude and longitude of a place in javascript by cityget the city name based on longtitude and latitude google mapsswitch case for lat long giving citz namefind suburb using geolocation apiget city from lat long and use itget city from lat lon javascriptapi geocode free lat longget city name from latitude and longitude in node jsapi get city location with lat longget city from geolocation in nodejsget city name from latitude and longitudefind a city with latitude and longitude apiget state or city from lat lngget coordinates of city apiapi get city with lat and logget city by latitude and longitude apigeocode get city name from long latapi city coordinatesjs city to coordinatesconvert city name to latitude longitude javascripthow to get latitude and longitude from city name in javascript without google mapsapi to get country from coordinatesjavascript get city with latitudeget location name from latitude and longitude javascriptget the geolocation latitude value from phpget country city name from latitude and longitude laravelapi to convert lat and long to city nameretrieve lat lon from city nameget user details from lat long city 2c countget city name from latitude and longitude google apican you convert latitude and longitutle to city name javascriptapi to convert lat long to pinget city code from latitude longitudehow to get city name from geocoding in angularhow to get gps coordinates from latitude and longitude in phphow to get latitude and longitude using place name 3fhow to determine city using longitude and latitudeswitch case for lat long giving city nameconvert latitude and longitude to city in javascriptjs city to lang long apiget city name from latitude and longitude without apihow to get current location latitude and longitude in phphow to get city name by latitude and longitude in javascriptget location name from latitude and longitude angularget city name from latitude and longitude in php using geocode api