Ich mache Wetter App, die getCoords Funktion aktiviert einmal 'finde mich!' Schaltfläche geklickt wird:JS - Geolocation-Funktion Fehler, während alles funktioniert OK
getCoords(e){
e.preventDefault();
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition((position) =>{
const long = position.coords.longitude,
lat = position.coords.latitude;
console.log(`long ${long} and lat ${lat}`);
this.setMessage('http://api.openweathermap.org/data/2.5/forecast?lat='+lat+'&lon='+long+"&APPID=mykey");
}).bind(null,this);
}
}
Wie ich aus den Ergebnissen zufrieden bin, was es gibt und es funktioniert, wie ich erwarten würde ich viele Fehler in der Konsole, die mich ein wenig besorgt fühlen. firefox:
TypeError: navigator.geolocation.getCurrentPosition(...) is undefined
Chrom und Opera:
Uncaught TypeError: Cannot read property 'bind' of undefined at WeatherApp.getCoords (app.bundle.js?49cb1f92ba06aee2ea42:374)
Opera:
Failed to load resource: the server responded with a status of 404 (Not Found)
Die Funktion '.getCurrentPosition()' gibt keine andere Funktion zurück, aber Ihr Code wird so geschrieben, als ob er es getan hätte. – Pointy