如何在javascript中为变量分配数据库值
这里mapid是从数据库中分配值的变量
var geocoder;
var map;
var mapid
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(mapid);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeControl: false,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
if (geocoder) {
geocoder.geocode( { }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title:address
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} else {
}
} else {
}
});
}
}
<div id="map_canvas" style="width: 270px; height: 267px;">
</div>
请在这里分享答案。