首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google地图API:无法显示地图

google地图API:无法显示地图
EN

Stack Overflow用户
提问于 2014-04-09 19:03:54
回答 1查看 58关注 0票数 0

它显示do you want to share your location in url,但不显示地图。所以我想知道哪里会出问题?但它在IE和firefox上显示,但在safari和chrome上不显示

代码语言:javascript
复制
$(document).ready(function(){
initialize();
$("#btInit").click(function(){

    navigator.geolocation.getCurrentPosition(onSuccess);  
}); //call this function when the user click
});

var map;

//MAP

代码语言:javascript
复制
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
 var mapOptions = {
zoom: 17
};
}

//地理位置

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2014-04-09 20:07:22

这是一个范围的问题。我是这样修复的(jsfiddle这里:http://jsfiddle.net/gjacobs/D9ug8/1/):

代码语言:javascript
复制
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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22960572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档