开发者

about location change

hi i'm new to android programming, i want to ask about location API, i struggle to a problem here when i'm using a network provider to obtain location data, i view my log in logcat there is a change in my location data 12-19 23:22:08.556: DEBUG/NetworkLocationProvider(1974): onCellLocationChanged [9994,65172896], but i just can't seem update it in my phone, even the requestLocationUp开发者_运维知识库date listener method onLocationchanged() doesn't update,can you answer this?here is my code :

private void initLocation(){
     locman = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     lokasi = locman.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
     locman.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,1 , 0,this);
     lat.setText("Latitude : 0 ");
     lon.setText("Longitude : 0 ");
}

 @Override
 public void onLocationChanged(Location location) {
  lon.setText("Longitude : "+String.valueOf(lokasi.getLongitude()));
  lat.setText("Latitude : "+String.valueOf(lokasi.getLatitude()));
  Toast.makeText(this, lokasi + "",2000).show();
 }

i can find anything wrong,but my location still doesn't change even when the logcat react to this thx


Try using Location.GPS_PROVIDER instead of Location.NETWORK_PROVIDER. You will also need the following permission in your manifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜