2016-06-17 7 views
1

Ist Geolocation google. Beispiel nahm von hier https://developers.google.com/maps/documentation/javascript/examples/map-geolocation?hl=ru. JAVASCRIPT + HTML wurde kopiert und auf einem virtuellen Host http://test.ru auf localhost abgelegt. Ein Browserschlüssel erstellt und hinzugefügt. Die Karte ist geladen, aber Geolocation in Google Chrome nicht ausgeführt. Sag mir, was das Problem ist. Hier ist der Code:Geolocation funktioniert nicht in Google Chrome

// Note: This example requires that you consent to location sharing when 
// prompted by your browser. If you see the error "The Geolocation service 
// failed.", it means you probably did not give permission for the browser to 
// locate you. 
function initMap() { 
    var map = new google.maps.Map(document.getElementById('map'), { 
    center: {lat: -34.397, lng: 150.644}, 
    zoom: 6 
    }); 
    var infoWindow = new google.maps.InfoWindow({map: map}); 
    // Try HTML5 geolocation. 
    if (navigator.geolocation) { 
    navigator.geolocation.getCurrentPosition(function(position) { 
    var pos = { 
    lat: position.coords.latitude, 
    lng: position.coords.longitude 
    }; 
    infoWindow.setPosition(pos); 
    infoWindow.setContent('Location found.'); 
    map.setCenter(pos); 
}, function() { 
    handleLocationError(true, infoWindow, map.getCenter()); 
}); 
    } else { 
// Browser doesn't support Geolocation 
handleLocationError(false, infoWindow, map.getCenter()); 
} 
} 
function handleLocationError(browserHasGeolocation, infoWindow, pos) { 
    infoWindow.setPosition(pos); 
    infoWindow.setContent(browserHasGeolocation ? 
        'Error: The Geolocation service failed.' : 
        'Error: Your browser doesn\'t support geolocation.'); 
}` 
+0

Sie erhalten einen Fehler auf der Konsole? Stellen Sie sicher, dass Sie den Standortdienst in Ihrem Chrome-Browser zulassen –

Antwort

0

das Problem ist, dass, da Chrom 50, ein Sicherheitsupdate die posibility von Geolocation entfernt, ohne http s Protokoll. da Sie diese URL versuchen http: //test.ru wird es nicht funktionieren. Google details

Ich hoffe, es hilft. Grüße.