【发布时间】:2017-05-16 07:23:04
【问题描述】:
在 Firefox 中,我的标记显示正常,但在 chrome 中,它不显示任何内容。 我认为 chrome 不允许我访问当前用户位置。 因为标记显示了用户的当前位置。
我的代码:
initialize();
function initialize()
{
map = new google.maps.Map(document.getElementById('googleMap'), {
center: {lat: 35.6961111, lng: 51.4230556},
zoom: 13
});
}
getLocation();
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
getAddress(lat,lng);
initialize(lat,lng);
}
//START FIND LOCATION
var geocoder = new google.maps.Geocoder();
var marker = null;
var map = null;
function initialize(lat,lng) {
//var $latitude = document.getElementById('latitude');
// var $longitude = document.getElementById('longitude');
var latitude = lat;
var longitude = lng;
var zoom = 16;
var LatLng = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
zoom: zoom,
center: LatLng,
panControl: false,
zoomControl: false,
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);
if (marker && marker.getMap) marker.setMap(map);
marker = new google.maps.Marker({
position: LatLng,
map: map,
title: 'Drag Me!',
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function(marker) {
var latLng = marker.latLng;
getAddress(latLng.lat(),latLng.lng());
});
}
我的网址:
【问题讨论】:
-
有一些关于如何在developers.google.com/web/fundamentals/native-hardware/… 上处理地理位置的谷歌代码示例(这不是下面答案中的链接)..
标签: javascript google-maps google-chrome google-maps-api-3