2014-04-09 6 views
0

표시 하시겠습니까? 귀하의 위치를 ​​URL에 공유하고 싶지만지도를 표시하지 않습니까? 어디서 잘못 될 수 있는지 궁금합니다. 하지만 사파리와 크롬Google지도 API :지도를 표시 할 수 없음

$(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); 
+0

나는이 링크를 따라야 만한다. http://www.paulund.co.uk/how-to-use-geolocation-api-with-google-maps –

답변

0

그것은 범위에 문제의에 IE와 파이어 폭스하지만 표시되지에서 보여줍니다. (: http://jsfiddle.net/gjacobs/D9ug8/1/를 jsfiddle 여기) : 그래서처럼 고정

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); 
}); 

그러나 당신이 청소기는 자바 스크립트를주는 다른 옵션도있다.

+0

Firefox와 ie에 표시되지만 크롬과 사파리에는 보이지 않는다. – noooooooo

관련 문제