私のjavascriptスキルは最高ではないので、私はただ愚かなことをしていると思います。次のコードは、空白の灰色のマップを生成します。
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
geocoder = new google.maps.Geocoder();
var address = "Minneapolis, MN";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
addresslatlng = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());
}
else
{
alert(status);
}
});
var mapOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: addresslatlng
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directions-panel'));
}
ただし、単に「center:addresslatlng」を次のように変更した場合:
center: new google.maps.LatLng(-34.397, 150.644)
正常に動作します。
latとlngを使用してみましたが、どちらも機能しません。
center: new google.maps.LatLng(lat, lng)
何か案は?