usrZorg
Junior Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Get coordinates by address</title> <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script> </head> <body> <p id="coordinates"></p> <script type="text/javascript"> var address = "Moscow, RU"; var xy = getcoordinates(address); function getcoordinates(address) { var LatLng; geocoder = new google.maps.Geocoder(); if (geocoder) { geocoder.geocode({ 'address': address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { //results[0].geometry.location //alert("position: " + results[0].geometry.location); console.log("position: " + results[0].geometry.location); LatLng = "position: " + results[0].geometry.location; //console.log(LatLng); //alert(LatLng); } else { LatLng = "No results found"; } } else { LatLng = "Geocode was not successful for the following reason: " + status; } }); } return(LatLng); } document.getElementById("coordinates").innerHTML = xy; </script> </body> </html> |