0
我有這個腳本正在工作。我可以拖動標記,並使用經度和緯度填充兩個文本輸入字段。我有變量「地址」,其中包含州和縣。我應該如何改變我的代碼,使其不再使用地址變量而是使用靜態的經度和緯度變量。所以最初我想讓地圖位於地址位置的中間。如何在谷歌地圖中使用地址而不是經度和緯度?
function selectState(state_id){
if(state_id!="-1"){
loadData('city',state_id);
var e = document.getElementById("state");
var stateloc = e.options[e.selectedIndex].value;
var address = state_id + stateloc;
var $latitude = document.getElementById('latitude');
var $longitude = document.getElementById('longitude');
var latitude = 35.00636021320537
var longitude = -53.46687316894531;
var zoom = 12;
var LatLng = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
zoom: zoom,
center: LatLng,
panControl: false,
zoomControl: true,
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map'),mapOptions);
var marker = new google.maps.Marker({
position: LatLng,
map: map,
title: 'Drag Me!',
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function(marker){
var latLng = marker.latLng;
$latitude.value = latLng.lat();
$longitude.value = latLng.lng();
});
}else{ $("#city_dropdown").html("<option value='-1'>Select city</option>");
}
}
HTML
<li>
<label for="lat">Latitude:</label>
<input id="latitude" placeholder="latitude" name="lat" type="text" class="text" />
</li>
<li>
<label for="lon">Longitude:</label>
<input id="longitude" placeholder="longitude" name="lon" class="text" type="text"/>
</li>
<div id="map" style="width: 460px; height: 350px;"></div>
酷閱讀更多關於谷歌地理編碼!我得到它的工作,仍然能夠拖動標記和填充文本輸入的經度和緯度。謝啦! –
很高興它有幫助。 – Gaurav
複製([代替經度和緯度與谷歌地圖API使用地址] http://stackoverflow.com/questions/15925980/using-address-instead-of-longitude-and-latitude-with-google-maps-api ) – geocodezip