我從Google API獲取了此代碼,我想提取該位置的經緯度,以便我可以找到它周圍的最近的10個位置。
的Javascript:使用Google API獲取位置的經緯度並傳遞變量
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=mykeyhere&sensor=true"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(14.5833, 120.9667);
var mapOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
身體:
<body onload="initialize()">
<div id="map-canvas" style="width: 320px; height: 480px;"></div>
<div>
<input id="address" type="textbox">
<input type="button" value="Encode" onclick="codeAddress()">
</div>
</body>
有一個文本框,當用戶將進入一個位置和JavaScript把一個標記上的谷歌地圖。我怎麼能分別得到經緯度和傳遞給html身體?
我想要做的是在獲得座標後,我將搜索距離數據庫最近的10個位置(經緯度爲字段)。然後,我怎麼能把標記放在地圖上最近的10個位置?請幫幫我。謝謝!
這個代碼是你的全部嗎? – putvande
我添加了正文。 @putvande –
我的意思是,你有代碼來查詢數據庫,並得到結果回來等 – putvande