2016-06-14 56 views
0

我从googleApiClient获取位置,当我在google的alert提示生成器中单击yes时,则使用onActvityResult检查用户是否单击是,然后设置我的文本查看该位置,我没有在同一时间得到最后的位置,所以我用while while循环,这是一个很好的做法吗? 这些是获取位置的函数,我在我的活动中将它设置为onActivityResult方法中的文本视图,请告诉我,使用这个方法虽然是一个好的做法?使用do while循环从google api获取位置

public Location getCurrentLatLong() { 
    checkLastLocation(); 
    Log.w("checkingsAct", mLastLocation + ""); 
    if(mLastLocation != null) { 
     Log.w("checkingsAct", mLastLocation+""); 
     latitude = mLastLocation.getLatitude(); 
     longitude = mLastLocation.getLongitude(); 
     mLastLocation.setLatitude(latitude); 
     mLastLocation.setLongitude(longitude); 
     Log.w("discheck", latitude + "" + " " + longitude); 
    } 
    return mLastLocation; 

} 
public void checkLastLocation() { 
    do { 
     mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); 
     Log.w("checkingsAct", mLastLocation + "do called"); 
    } while(mLastLocation == null); 

回答

0

您需要请求位置更新像下面

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationListener); 

如果一旦locaiton更新后,您会得到回电void onLocationChanged(Location location)方法。

+0

和TextView的 –

+0

然后在这个位置改变方法,我可以用设置文本是的,你可以用这个方法来设置TextView的 – Chandrakanth

+0

OK,日Thnx,我试图 –