我目前正在我的php项目中实施谷歌地图。我根据数据库值显示标记。在ajax调用中,标记正在改变。我想在谷歌地图上显示标记而不刷新地图。
function load() {
var map = new google.maps.Map(document.getElementById("offers-map"), {
center: new google.maps.LatLng(44.910398, -93.271976),
zoom: 15,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
/* var infoWindow = new google.maps.InfoWindow(); */
// Change this depending on the name of your PHP file
$.ajax({
type: "POST",
url: "logic_abstract.php",
success: function(msg){
//alert(msg);
// call the count values
countthedata(msg);
msg = jQuery.parseJSON(msg);
var len1 = Object.keys(msg).length;
if(msg =="")
{
swal("There is no data that matches your search criteria");
}
for (i=0;i<len1;i++){
var mapimgpath = msg[i].imagepath;
var type = msg[i].reason_name;
var zip = msg[i].zip;
var addr = msg[i].addr;
var repname = msg[i].repname;
var point = new google.maps.LatLng(parseFloat(msg[i].latitude), parseFloat(msg[i].longitude));
var html = "<div class='gm-style-iw'><b>" + type + "</b><br>" + repname + "<br>" + addr + " , " + zip+"</div>";
var icon='<?php echo BASE_PATH;?>/mapview/'+mapimgpath;
marker = new google.maps.Marker({ map: map, position: point,icon: icon});
bindInfoWindow(marker, map, infoWindow, html);
}
}
});
}
答案 0 :(得分:0)
//create map as global
var map = new google.maps.Map(document.getElementById("offers-map"), {
center: new google.maps.LatLng(44.910398, -93.271976),
zoom: 20,
mapTypeId: 'roadmap'
});
//create global marker array
var gMarkers=[];
//global variable for length
var locationLength=0;
// call in loading time
// remove the previous markers
for(i=0; i<gMarkers.length; i++){
gMarkers[i].setMap(null);
}
gMarkers=[];//empty the global marker array
var map = new google.maps.Map(document.getElementById("offers-map"), {
center: new google.maps.LatLng(44.910398, -93.271976),
zoom: 15,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
/* var infoWindow = new google.maps.InfoWindow(); */
// Change this depending on the name of your PHP file
$.ajax({
type: "POST",
url: "logic_abstract.php",
success: function(msg){
//alert(msg);
// call the count values
countthedata(msg);
msg = jQuery.parseJSON(msg);
var len1 = Object.keys(msg).length;
if(msg =="")
{
swal("There is no data that matches your search criteria");
}
for (i=0;i<len1;i++){
var mapimgpath = msg[i].imagepath;
var type = msg[i].reason_name;
var zip = msg[i].zip;
var addr = msg[i].addr;
var repname = msg[i].repname;
var point = new google.maps.LatLng(parseFloat(msg[i].latitude), parseFloat(msg[i].longitude));
var html = "<div class='gm-style-iw'><b>" + type + "</b><br>" + repname + "<br>" + addr + " , " + zip+"</div>";
var icon='<?php echo BASE_PATH;?>/mapview/'+mapimgpath;
marker = new google.maps.Marker({ map: map, position: point,icon: icon});
bindInfoWindow(marker, map, infoWindow, html);
}
}
});