Al fin después de mucho luchar hemos encontrado la respuesta de esta incógnita que algunos lectores de nuestro sitio tienen. Si tienes algo más que compartir no dudes en dejar tu información.
Ejemplo: obtener la ciudad desde la ubicación html
DOCTYPEhtml><html><head><metaname="viewport"content="initial-scale=1.0, user-scalable=no"/><metahttp-equiv="content-type"content="text/html; charset=UTF-8"/><title>Reverse Geocodingtitle><scripttype="text/javascript"src="http://maps.googleapis.com/maps/api/js?sensor=false">script><scripttype="text/javascript">var geocoder;if(navigator.geolocation)navigator.geolocation.getCurrentPosition(successFunction, errorFunction);//Get the latitude and the longitude;functionsuccessFunction(position)var lat = position.coords.latitude;var lng = position.coords.longitude;codeLatLng(lat, lng)functionerrorFunction()alert("Geocoder failed");functioninitialize()
geocoder =newgoogle.maps.Geocoder();functioncodeLatLng(lat, lng)var latlng =newgoogle.maps.LatLng(lat, lng);
geocoder.geocode('latLng': latlng,function(results, status)if(status == google.maps.GeocoderStatus.OK)console.log(results)if(results[1])//formatted addressalert(results[0].formatted_address)//find country namefor(var i=0; i<results[0].address_components.length; i++)for(var b=0;b<results[0].address_components[i].types.length;b++)//there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriateif(results[0].address_components[i].types[b]=="administrative_area_level_1")//this is the object you are looking for
city= results[0].address_components[i];break;//city dataalert(city.short_name+" "+ city.long_name)elsealert("No results found");elsealert("Geocoder failed due to: "+ status););script>head><bodyonload="initialize()">body>html>
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)