1
住所を取得し、その住所から緯度/経度を取得し、地図上にマーカーをドロップするアプリを作成しました。しかし、私は、他のビジネスがあるショッピングセンターで、ビジネスの正確な場所にマーカーを配置する必要がある場所に突入して問題を起こしました。マーカーは、私が必要とするビジネスではなく、そのショッピングセンターの1つのビジネスに配置されています。Google Maps api geoコードのアドレスと場所のマーカーをショッピングセンターの正確な場所に置く
私がケルトハウスパブで必要とするとき、マーカーはビジネス "スレッドインクメディア"に配置されています。どんな助けもありがとう。ここで
が私のJavaScriptの出力です:
var locations =[[loc0='Celtic House Pub','16522 Keystone Blvd Parker, CO 80134',0],];
var mapOptions = {
zoom: 18,
center: {lat:39.53191, lng:-104.79641},
scrollwheel:false,
}
var geocoder;
var map;
function initMap() {
var bounds = new google.maps.LatLngBounds();
var transitLayer = new google.maps.TransitLayer();
var trafficLayer = new google.maps.TrafficLayer();
var bikeLayer = new google.maps.BicyclingLayer();
map = new google.maps.Map(document.getElementById('map-129'),
mapOptions);
geocoder = new google.maps.Geocoder();
for (i = 0; i < locations.length; i++) {
var html;
geocodeAddress(locations, i);
}
}
function geocodeAddress(locations, i) {
var title = locations[i][0];
var address = locations[i][1];
var url = locations[i][2];
var latitude;
var longitude;
geocoder.geocode({
'address': locations[i][1]
},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: title,
animation: google.maps.Animation.DROP,
address: address,
latitude: latitude,
longitude: longitude
})
infoWindow(marker, map, title, address, url, latitude, longitude);
map;
} else {
alert("geocode of " + address + " failed:" + status);
}
});
}
var html;
var iw;
function infoWindow(marker, map, title, address, url, latitude, longitude, iw) {
html ="<div class='place-card place-card-large' jstcache='128'>"+
"<div class='place-desc-large'>"+
"<div class='place-name' jsan='7.place-name' jstcache='36'>" + title + "</div>"+
"<div class='address' jsan='7.address' jstcache='37'>" + address + "</div>"+
"</div>"+
"<div class='navigate' jstcache='38'>"+
"<div class='navigate' jsaction='placeCard.directions'>"+
"<a class='navigate-link' href='https://maps.google.com/maps/dir//"+encodeURI(title).replace(/%20/g, "+")+"," + address + "/@" + latitude.toFixed(5) + "," + longitude.toFixed(5) + ",17z/data=!4m8!4m7!1m0!1m5!1m1!1s' jstcache='60' target='_blank'>"+
"<div class='icon navigate-icon'></div>"+
"<div class='navigate-text'>Directions</div>"+
"</a>"+
"</div>"+
"</div>"+
"<div class='maps-links-box-exp'>"+
"<div class='google-maps-link' jsan='7.google-maps-link' jstcache='49'>"+
"<a href='https://maps.google.com/maps/place/" + address + "' target='_blank'>View larger map</a>"+
"</div>"+
"</div>"+
"</div>"+
"</div>"+
"</div>"+
"</div>";
iw = new google.maps.InfoWindow({
content: html,
maxWidth: 350
});
google.maps.event.addListener(marker, 'click', function() {
iw.open(map, marker);
});
}