वर्तमान में मैं बस अपनी वेबसाइट से जो परीक्षण करता हूं उसे एक टेस्ट सर्वर पर अपलोड करता हूं और यह मुफ्त है, स्थानीय रूप से यदि Google मानचित्र एपीआई काम करता है और मुझे वह स्थान दिखाता है जहां मैं वर्तमान में हूं। लेकिन जब मैंने सर्वर पर अपनी वेबसाइट अपलोड की और सब कुछ ठीक दिखने के लिए आवश्यक सब कुछ संशोधित किया, तो Google मानचित्र API का वह हिस्सा सही तरीके से काम करना बंद कर दिया।Google मानचित्र API सर्वर पर क्यों काम नहीं करता है? [त्रुटि: जिओलोकेशन सेवा विफल]
गूगल मैप्स एपीआई कोड:
Error: The Geolocation service failed
मैं स्क्रिप्ट, कि अक्षुण्ण बनी की कुछ भी संशोधित नहीं है:
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 12
});
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('Esta es tu ubicacion');
map.setCenter(pos);
var icon = {
url: "vista/multimedia/imagenes/pointer.png", // url
scaledSize: new google.maps.Size(30, 30), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(0, 0) // anchor
};
var marker = new google.maps.Marker({
position: pos,
map: map,
title: 'marker with infoWindow',
icon: icon
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}, 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.');
}
त्रुटि है कि मैं पीछा कर रहा है।
कोड गूगल मानचित्र डाल करने के लिए:
<center><div id="map" style="height:500px;width:900px;margin-top:5%;"></div></center>
कोड
वेब कंसोल त्रुटि अपने संबंधित कुंजी
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA49iAee5kSTQ-whGT3A77H-PJsK5FzLCk&callback=initMap" async defer></script>
वर्तमान परिणाम के साथ एपीआई भेजने के लिए:
[Deprecation] getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS.