2016-09-14 9 views
0

私は私のアプリのコードのこの部分を使用している「反応-ネイティブジオコーダ」ライブラリ、使用しています:Geocoder.geocodePosition未定義の関数エラー

//reverse - geocoding 
var NY = { 
     lat: 40.7809261, 
     lng: -73.9637594 
    }; 

Geocoder.geocodePosition(NY).then(res => { 
    // res is an Array of geocoding object (see below) 
    //location details goes here 
}) 
.catch(err => console.log(err)) 

しかし、エラーを取得:

geocodePostion is undefined function

私は"react-native": "0.31.0", "react-native-geocoder": "^0.4.5"を使用しており、ライブラリに記載されている設定手順に従っています。

+0

get locationの取得に「Geolocation」https://facebook.github.io/react-native/docs/geolocation.htmlを使用してみませんか? –

+0

エラーメッセージにgeocodePositionのiがありませんが、コードにはそこにあります。 – lucash

答えて

2

私はそれがこのcode.Iによって固定されてしまった緯度と経度の場所マークを取得しようとしていた

var myAddress = '' 

      var NY = { 
        lat: this.state.position.coords.latitude, 
        lng: this.state.position.coords.longitude 
        }; 

Geocoder.fallbackToGoogle(MY_KEY);//MY_KEY -- enabled the key googleMapAPI portal. 
// use the lib as usual 
let ret = Geocoder.geocodePosition(NY).then((res)=> 
{ 
    console.log(res) 
    myAddress = res["0"].formattedAddress 
    console.log(myAddress); 
    this.setState({ 
      MyAddress: myAddress 
     }); 
}) 
console.log(this.state.MyAddress); 

私は「反応するネイティブ」を使用しています:「0.31.0」を、「react- native-geocoder ":" 0.4.5 "とし、ライブラリで述べた設定手順に従ってください。