-1
私はマップを生成するためにGoogle map apiを使用しています。私はGoogle Chromeで地図を生成することができますが、それはFirefoxで動作していない次のコードを使用することによって。さらに、コンソールにはJSエラーがなく、対応するhtmlはFirefoxで生成されません。Google Mapがfirefoxに表示されていません
var map;
var marker;
var lat;
var lng;
var myLatlng;
var geocoder = new google.maps.Geocoder();
var infowindow = new google.maps.InfoWindow();
function initialize(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
myLatlng = new google.maps.LatLng(-23.69748,133.88362);
}
function showPosition(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
show_map(lat,lng);
}
function show_map(lat,lng){
var mapOptions = {
zoom: 18,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("myMap"), mapOptions);
map.setCenter(new google.maps.LatLng(lat,lng));
map.setZoom(8);
marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(lat,lng),
draggable: true
});
geocoder.geocode({'latLng': new google.maps.LatLng(lat,lng) }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
}
}
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
あなたはフィドルを投稿できますか? – xxxmatko
ジオコーダ=新しいgoogle.maps.Geocoder(); infowindow =新しいgoogle.maps.InfoWindow(); - これらの行をinitialize()の中に入れてみてください。 (宣言をグローバルに保つことができます)。 –
'navigator.geolocation'がfalseの場合、' myLatlng'を指定して 'show_map'を呼び出しません。 – GramThanos