Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Here is code which gets latitude and longitute when entered a location.I believe that my code right according to my knowledge.but i get a blank page after entering a place.

Here is the code:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    var url="http://maps.googleapis.com/maps/api/geocode/json?address=";
    var query;
    var sensor="&sensor=false";
    var callback="&callback=?";


    $("button").click(function(){
          query=$("#query").val();
          $.getJSON(url+query+sensor+callback,function(json){

             $('#results').append('<p>Latitude : ' + json.results.geometry.location.lat+ '</p>');
             $('#results').append('<p>Longitude: ' + json.results.geometry.location.lng+ '</p>');

});


    });
});


</script>

</head>
<body>

<input type="text" id="query" /><button>Get Coordinates</button>
<div id="results"></div>

</body>
</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
255 views
Welcome To Ask or Share your Answers For Others

1 Answer

In Google Maps Javascript V3 you can access the geocoding service using the google.maps.Geocoder class.

var myAddressQuery = 'O. J. Brochs g 16a, Bergen';
var geocoder = new google.maps.Geocoder(); 
geocoder.geocode(
    { address : myAddressQuery, 
      region: 'no' 
    }, function(results, status){
      // result contains an array of hits.
});

https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...