PHP: Как изменить маркеры, не обновляя карту Google в вызове PHP ajax?

В настоящее время я внедряю Google Maps в моем проекте PHP. Я показываю маркеры в соответствии со значениями базы данных. В вызове ajax маркеры меняются. Я хочу показать маркеры на карте Google без обновления карты.

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

Решение

//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);
}
}
});
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]