2017-11-26 12 views
0

날씨 앱을 사용하고 있는데 getCoords 함수가 활성화되면 '나를 찾습니다!' 나는 그것이주는 결과에서 행복으로JS - geolocation 함수 오류, 모든 작업이 정상적으로 작동합니다.

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); 
} 
} 

와 나는 나를 조금 걱정 느낌 콘솔에서 오류를 많이 얻을 기대로 작업을 수행 버튼을 클릭합니다. 파이어 폭스 :

TypeError: navigator.geolocation.getCurrentPosition(...) is undefined

크롬과 오페라 :

Uncaught TypeError: Cannot read property 'bind' of undefined at WeatherApp.getCoords (app.bundle.js?49cb1f92ba06aee2ea42:374)

오페라 :

Failed to load resource: the server responded with a status of 404 (Not Found)

+0

'.getCurrentPosition()'함수는 다른 함수를 반환하지 않지만 코드는 마치 마치 마치 함수처럼 쓰여집니다. – Pointy

답변

0

당신은 구속력있는 '이'TU로 기능하지만, 반환 값.

'bind'는 Function 프로토 타입의 메소드입니다. 왜 바인드 콜을 사용하는지 모르겠습니다. 그냥 함수를 호출하기 전에 제거하거나 호출하십시오.

+0

나는 그것을 제거했다, 지금 어디 에나 그 ok – Jake11