0
モーダルポップアップでGoogleマップを表示するには、以下のコードを使用しています。しかし、Google Mapマーカーはモーダルの中央に表示されません。それは常に左隅に隠されています。Googleマップのマーカーがモーダルポップアップの中央に表示されない
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(0.0, 0.0);
var mapOptions = {
zoom: 14,
center: new google.maps.LatLng(0.0, 0.0),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function codeAddress(i) {
var address = document.getElementById('address'+i).value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
zoom:10,
position: results[0].geometry.location
});
google.maps.event.addListenerOnce(map, 'idle', function() {
google.maps.event.trigger(map, 'resize');
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
</script>
サンプルページで簡単にできます:)まず、LatLng varを使用しません。それを削除する(またはそれを使用する:)私が理解するところでは、マップがアイドルであるときにマップの再描画が呼び出されます。アイドルイベントが起きたことは確かですか? – Nico
変数から動的にLatLngを取得しています。その良い仕事。私はまた、マーカーを参照してください。それは左隅を示していました。私はどのように地図の中心に移動しますか?助けてください –
マニュアルmap.setCenter(latLng)が問題を解決していますか?はいの場合、マップセンターがgmapでうまく使用されていないことを意味します。この場合、再描画後にマップセンターを設定するだけです。 – Nico