Ich bin neu bei Javascript und habe bei geocode stecken geblieben, ich versuche, aktuellen Standort zu bekommen und seine placeid mit Geocode, wenn ich Passnummern auf die lat lang, es funktioniert gut sonst gibt es Alarm Geocoder aufgrund von ZERO_RESULTS fehlgeschlagen, der folgende Code funktioniert einwandfreiGeocoder wegen ZERO_RESULTS fehlgeschlagen
var currentLatitude= 23.2147721;
var currentLongitude =72.6446714;
function initialize() {
var geocoder = new google.maps.Geocoder;
var latlng = {
lat : currentLatitude,
lng : currentLongitude
};
console.log("Geocoder" + latlng);
geocoder.geocode({
'location' : latlng
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1].place_id);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
q
}
});
};
Code unten zeigt den Fehler.
var currentLatitude,currentLongitude;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
currentLatitude = parseFloat(position.coords.latitude);
currentLongitude = parseFloat(position.coords.longitude);
console.log("Latitude:"+currentLatitude+"Longitude:"+currentLongitude);
});
} else {
console.log("Geolocation is not supported by this browser.");
}
function initialize() {
var geocoder = new google.maps.Geocoder;
var latlng = {
lat : currentLatitude,
lng :currentLongitude
};
console.log("Geocoder" + latlng);
geocoder.geocode({
'location' : latlng
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1].place_id);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
};
die src, die ich verwendet habe, ist
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOURKEYHERE&callback=initialize">
jede Hilfe dankbar ist –