入力郵便番号で店舗のデータベースを検索し、それらを Google マップに POI としてマップし、「マップを表示」をクリックするとマップを表示するページがあります。私の問題は、1 回おきのクリックに対してのみマップが生成されるように見えることです。テーブルとマップの両方を生成するコードを提供しています (同じ ajax 呼び出し内で)。
より具体的には、私が言及しているクリックは、「マップを表示」クリックではなく、ajax コードを呼び出す検索機能のトリガーです。つまり、最初に郵便番号を検索すると、地図が表示されます。2 番目の検索では地図が得られず、3 番目の検索では地図が得られます...など...
どんな助けでも大歓迎です
コードは次のとおりです。
function retrieve_stores_in_prox(){
$('.trigger2').click(function() {
$("#map_store").each(function(){
if ($(this).css("display") == "none")
{
$(this).css("display", "block");
}
else
{
$(this).css("display", "none");
}
})
});
$(document).ready(function() {
$('#storeList').empty().trigger("update");
//initialize the store map
var redicon = new GIcon();
redicon.image = "images/redCircle.png";
redicon.iconSize = new GSize(11, 11);
redicon.iconAnchor = new GPoint(6, 6);
redicon.infoWindowAnchor = new GPoint(6,6);
$.ajax({
type: 'post',
url: 'trip_planner_store.php',
dataType: "xml",
cache: false,
data: {zip:$("#zip").val()},
success: function(data) {
var storemap = new GMap2(document.getElementById("map_store"), { size: new GSize(500,320) });
storemap.addControl(new GLargeMapControl());
storemap.addControl(new GMapTypeControl());
var lat1 = $(data).find('LAT1').text();
var lon1 = $(data).find('LON1').text();
storemap.setCenter(new GLatLng(lat1,lon1),8);
google.maps.event.trigger(storemap, 'resize');
$(data).find('STORE').each(function(index){
var lat = parseFloat($(this).find('LATITUDE').text());
var long = parseFloat($(this).find('LONGITUDE').text());
var marker = new GMarker(new GLatLng(lat,long), {
draggable: false,
title: ($(this).find('COMPANY_NAME').text()),
icon: redicon,
disableAutoPan: true,
supressMapPan: true
});
var html = {some stuff for the info window}
GEvent.addListener(marker, 'mouseover', function() {
// When clicked, open an Info Window
marker.openInfoWindowHtml(html);
});
storemap.addOverlay(marker);
//update the store table with the information
var storeList = {html markup for table};
//append the current row to the installer table
$('#storeList').append(storeList);
});
$('#storeList').trigger("update");
}
});
});
}