Я экспериментирую с Google Maps Platform
и, в частности, Maps JavaScript API
, который имеет Geolocation
функциональность документация, видимая здесь
У меня есть код, работающий на heroku с SSL, и он отлично работает для определения моего местоположения при использовании веб-браузера, однако при доступе к приложению через мобильное устройство Android; карта загружается, но там, но нет маркера с моим местоположением (несмотря на отметку разрешить отслеживание местоположения).
Мне интересно, какие еще положения я должен внести в приведенный ниже код.
Код
<!DOCTYPE html>
<html>
<head>
<title>ConDodge Updated</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// Maps JavaScript API
// Runs on Google Maps Platform under Geolocation
// Note: If you see the error "The Geolocation service
// failed.", it means you have to use a live server that is https enabled and not http
// ie, herouku
var map, infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
});
infoWindow = new google.maps.InfoWindow;
// Try HTML5 geolocation.
if (navigator.geolocation) { // the navigator.geolocation property determines users location
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
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.');
infoWindow.open(map);
}
//app will detect iPhone and Android devices and scale accordingly
function detectBrowser() {
var useragent = navigator.userAgent;
var mapdiv = document.getElementById("map");
if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ) {
mapdiv.style.width = '100%';
mapdiv.style.height = '100%';
} else {
mapdiv.style.width = '600px';
mapdiv.style.height = '800px';
}
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=blablablablablabal®ion=GB&callback=initMap">
</script>
</body>
</html>