我有兩個腳本。一個州/縣下拉的時候會激活,它會進行地址查詢並轉到該特定的縣。我已經在窗體中填充了「經度」和「緯度」文本框。我正試圖將兩者結合起來。後者腳本使用靜態經度/緯度,我需要它使用像我在第一個腳本中使用的地址。在試圖將這兩者結合起來的時候,我在我的代碼中有一處錯誤。地圖甚至不會出現。谷歌地圖地址沒有顯示
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 sAddress = state_id + stateloc;
var $latitude = document.getElementById('latitude');
var $longitude = document.getElementById('longitude');
//var latitude = 33.00636021320537
// var longitude = -93.46687316894531;
var zoom = 12;
var geocoder;
//var LatLng = new google.maps.LatLng(latitude, longitude);
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': sAddress}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
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,
position: results[0].geometry.location,
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();
});
//end geocoder check
}
else
{
alert("Geocode was not successful: " + status);
}
});
}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>
在你的HTML沒有地圖。 – geocodezip