2017-05-16 54 views
-2

在Firefox中,我的標記顯示罰款,但在鉻,它不顯示任何東西。 我認爲chrome不允許我訪問當前的用戶位置。 因爲標記顯示用戶的當前位置。鉻瀏覽器不顯示標記 - javascript

我的代碼:

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


      } 

我的網址:

http://www.khadamatchi.com/frontend/Index/addAddressByUser

+1

也有如何處理上https://developers.google.com/web/fundamentals/native-hardware/user-location/地理位置一些谷歌的代碼示例(這是不是在下面的答案的鏈接) –

+0

[getCurrentPosition on chrome break javascript]可能的重複(http://stackoverflow.com/questions/37125514/getcurrentposition-on-chrome-breaks-javascript) – geocodezip

+0

[navigator.geolocation在google chrome中無法正常工作] (http://stackoverflow.com/questions/37415413/navigator-geolocation-not-working-in-google-chrome) – geocodezip

回答