它显示do you want to share your location in url,但不显示地图。所以我想知道哪里会出问题?但它在IE和firefox上显示,但在safari和chrome上不显示
$(document).ready(function(){
initialize();
$("#btInit").click(function(){
navigator.geolocation.getCurrentPosition(onSuccess);
}); //call this function when the user click
});
var map;//MAP
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var mapOptions = {
zoom: 17
};
}//地理位置
function onSuccess(position){
var myLat = position.coords.latitude;
var myLong = position.coords.longitude;
var latLng = new google.maps.LatLng(myLat, myLong);
map.setCenter(latLng);
google.maps.event.addDomListener(document, initialize);发布于 2014-04-09 20:07:22
这是一个范围的问题。我是这样修复的(jsfiddle这里:http://jsfiddle.net/gjacobs/D9ug8/1/):
jQuery(document).ready(function () {
// Ask for permission
navigator.geolocation.getCurrentPosition(function(position){
var myLat = position.coords.latitude;
var myLong = position.coords.longitude;
var latLng = new google.maps.LatLng(myLat, myLong);
map.setCenter(latLng);
});
var map;
var centerPosition = new google.maps.LatLng(40.747688, -74.004142);
var options = {
zoom: 16,
center: centerPosition,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map($('#map')[0], options);
});但也有其他选择,让你更干净的JavaScript。
https://stackoverflow.com/questions/22960572
复制相似问题