8個のPHPファイルを含むメインのPHPファイルがあります。私はブートストラップのクラス "Modal"を使用し、私は各モーダルでGoogleマップを使用します。だから私はGoogleマップを表示するための異なるIDを持っていますが、機能は同じです。それは、各モーダルポップアップの1つが、機能が解雇され、Googleマップを示すことを意味します。私は各IDに8つの異なる機能を実装しています。異なるIDを持つ1つの関数を起動する方法
私が望むのは、1つの機能だけで実装する方法はありますか?だから、もっとはっきり言うこと
、id = 1
とモーダルポップアップあれば、それは<div id="location_incident1">
にしてid = 2
とモーダルポップアップ場合は、Googleマップを示し、それは<div id="location_incident2">
でグーグルマップを示しており、id = 3
とモーダルポップアップあれば、それは<div id="location_incident3">
でグーグルマップを示し、そうです。 、あなたは関数の外map3
、marker3
、...変数を保存する必要がない場合は
function locationOfIncident3(current)
{
var lat = current.coords.latitude;
latIncident = lat;
var lon = current.coords.longitude;
lonIncident = lon;
var mapOption={
center: new google.maps.LatLng(lat, lon),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map3 = new google.maps.Map(document.getElementById('location_incident3'), mapOption);
marker3 = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
map: map3,
draggable: true,
title: 'Location of Incident'
});
google.maps.event.addListener(marker3, 'dragend', function(res){
latIncident = res.latLng.lat();
lonIncident = res.latLng.lng();
getAddress3(latIncident, lonIncident);
});
}
あるSimpyは、2番目のパラメータとして関数にIDを渡す... – CBroe
何らかの理由 'latIncident '、' map3'、...は、 'var map3'とは対照的に、グローバル変数である必要があります、...? – Aprillion