良い一日、
Google マップにマーカーを追加しようとしていますが、すべてのマーカーが表示されるわけではありません。最初の住所マーカーのみが表示されます。以下のコードを参照してください。
//Search Button Event Handler
function getAccounts() {
//Search where City contains data
var Search = SearchText.value;
//alert("You have inserted: " + Search + " as a city");
if (Search != "") {
retrieveMultiple("AccountSet", "substringof('" + Search + "',Address1_City)", SearchCompleted, null);
}
//Retrieve all Accounts
else {
retrieveMultiple("AccountSet", null, SearchCompleted, null);
}
}
//Callback - Search Success
function SearchCompleted(data, textStatus, XmlHttpRequest) {
if (data && data.length > 0) {
for (var i=0; i < data.length; i++) {
var result = data[i];
var address = (data[i].Address1_Line1 + ", " + data[i].Address1_City + ", " + data[i].Address1_StateOrProvince + ", " + data[i].Address1_Country);
showAddress(address);
alert(result.Address1_Line1 + ", " +result.Address1_City + ", " + result.Address1_StateOrProvince + ", " + result.Address1_Country);
}
}
else {
alert('No records!');
}
}
function showAddress(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address}, function (result, status) {
if (status == google.maps.GeocoderStatus.OK) {
var myOptions = {
zoom: 3,
center: result[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
//map.setCenter(result[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: result[0].geometry.location
});
} else {
Alert("Geocode was not successful for the following reason: "+ Status); // address not found
}
});
}
// ]]>
alert() は取得されたすべての情報を表示するため、情報が適切に取得されていることがわかります