2016-12-05 33 views
0

當我沒有結束捏地圖時會調用此方法,有無論如何解決這個問題嗎?onRegionChangeComplete被調用的次數太多,而不是當真的事件結束時

http://imgur.com/VtKeC1g

下面是代碼

<MapView 
    style={{flex:1}} 
    region={{ 
    latitude: parseFloat(this.state.initialPosition.coords.latitude), 
     longitude: parseFloat(this.state.initialPosition.coords.longitude), 
    latitudeDelta, 
    longitudeDelta, 
    }} 
    showsUserLocation={true} 
    onRegionChangeComplete={(region) => { 
     console.log('onRegionChangeComplete called!'); 
    }} 
/> 

回答

0

我胡斯托解決這個問題作出的setTimeout!這裏是如何

<MapView 
    style={{flex:1}} 
    showsUserLocation={true} 
    onRegionChange={(region) => { 
     if(this.timeout){ 
      clearTimeout(this.timeout); 
     } 
     this.timeout = setTimeout(() => { 
       this.getDoctorsByGeolocation(region); 
     },1000); 
    }} 
/> 

我希望這可以幫助任何人!

相關問題