我在我的网页上使用谷歌标记。使用PHP页面从数据库中获取纬度,经度,名称和详细信息,然后使用$ .post方法在jquery上使用它。
<?php
//Basic environment setup (error handling and logging, cookies/sessions, php directives etc)
require_once $_SERVER['DOCUMENT_ROOT'] . '/../Config/path_config.php';
require_once C_PATH_UTILITY_MANAGER_PAGESETUP;
Page_Setup_Manager::setDefaultPageSettings();
require_once C_DIR_UTILITY_EVENTS_DATAACCESS;
$eventsdats=Eventsdata::getevents();
$temp=array();
foreach($eventsdats as $singlemapevent)
{
array_push($temp,array($singlemapevent['ename'],
(floatval($singlemapevent['latitude'])),
(floatval($singlemapevent['longitude'])),
($singlemapevent['edate']),
($singlemapevent['etime']),
($singlemapevent['edetail'])
));
}
echo json_encode($temp);
//Result[["Second Event",19.0554748,72.8497017,"17-12-2012","17:57 ","This is the
social detail;"],["Demo Event",19.2097381,72.8737017,"08-12- 2012","09:34 ","This event
was held in bhayander by ganesh mandhre"],]
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function initialize() {
markers=[];
temp=[];
final_markers=[];
$.post('maps_data.php',{},function(data){
},"json").done(function(data){
markers=(data);
$.each(data,function(index,value){
final_markers.push($.makeArray(value));
});
markers=final_markers;
});
alert(markers);
var latlng = new google.maps.LatLng(19.0554748, 72.8497017);
var settings = {
zoom: 10,
center: latlng,
visible:true,
mapTypeControl: true,
mapTypeControlOptions: {style:
google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style:
google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new
google.maps.Map(document.getElementById("map_canvas"), settings);
var infowindow = new google.maps.InfoWindow(), marker, i;
for (i = 0; i < markers.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(markers[i][1], markers[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">'+markers[i][0]+'</h1>'+
'<div id="bodyContent">'+
'<p>'+markers[i][3]+'</p>'+
'<p>'+markers[i][4]+'</p>'+
'<p>'+markers[i][5]+'</p>'+
'</div>'+
'</div>';
infowindow.setContent(contentString);
infowindow.open(map, marker);
}
})(marker, i));
}
}
</script>
<title>Untitled Document</title>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:350px"></div>
</body>
</html>
标记在firefox中可见,但在chrome和safari中不可见。错误是什么?我错误地使用了json吗?
答案 0 :(得分:0)
获取json数据时,必须在回调中处理它们。在此处显示ajax调用完成之前的地图和标记。将此呈现移至done
回调。