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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…