我使用php从数据库加载纬度和经度,并使用json编码方法转换为json变量。现在,当我尝试向json变量添加一个值时,地图变为空白。
$sql = "SELECT * FROM enrollments";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if($row["enrollmenttype"] == "pharmacy")
{
$pharmacyLatLng[$i] = "{lat: ".$row["lattitude"].", lng: ".$row["longitude"].", title: ".$row["title"]."},";
$pharmacyCounter = ++$i;
}
<script>
function LoadpharmacyMap() {
var mapOptions = {
center: new google.maps.LatLng(13.0102, 80.2157),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
//Create and open InfoWindow.
var infoWindow = new google.maps.InfoWindow({
content: contentString
});
for (var i = 0; i < pharmacymarkers.length; i++) {
var data = pharmacymarkers[i];
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
});
//Attach click event to the marker.
(function (marker, data) {
google.maps.event.addListener(marker, "mouseover", function (e) {
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>