Android用のphonegapアプリケーションを作成しています。私はJavascriptにあまり詳しくなく、「マップ」と呼ばれるマップを初期化する関数と、データベースからロードされているマーカーのリストをマップに表示する関数の2つの関数があるシナリオに遭遇しました。
ただし、私の質問は、別の機能で開始されたマップにマーカーを表示するように設定するにはどうすればよいですか?
編集ここにいくつかのコードがあります:
function map() {
...
map = new google.maps.Map(document.getElementById("map"), mapOptions);
...
}
function markers() {
var MarkerType1 = new google.maps.MarkerImage("/android_asset/www/assets/markerType1.png",
new google.maps.Size(29.0, 48.0),
new google.maps.Point(0, 0),
new google.maps.Point(14.0, 24.0)
);
var MarkerType2 = new google.maps.MarkerImage("/android_asset/www/assets/markerType2.png",
new google.maps.Size(29.0, 48.0),
new google.maps.Point(0, 0),
new google.maps.Point(14.0, 24.0)
);
var geocoder = new google.maps.Geocoder();
var eventList = $('ul#eventList').empty();
var eventPoints = $.ajax({
type: 'GET',
url: 'http://www.somedomain.com/loadEvents.php?&jsoncallback=?',
dataType: 'JSONp',
timeout: 5000,
success: function(data) {
$.each(data, function(i,item){
if (item.EventType == 1) {
new google.maps.Marker({
position: new google.maps.LatLng(item.latitude, item.longitude),
map: this.map,
icon: MarkerType1,
draggable:false
});
} else if (item.EventType == 2) {
new google.maps.Marker({
position: new google.maps.LatLng(item.latitude, item.longitude),
map: this.map,
icon: MarkerType2,
draggable:false
});
}
}
}
});
}