Get current coordinates

杀马特。学长 韩版系。学妹 提交于 2019-12-24 15:54:42

问题


Im writing an application that supposed to send coordinates in an SMS, but I've been struggling a bit with understanding how to get the coordinates.

At the moment I'm using this

  LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
  Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  longitude = location.getLongitude();
  latitude = location.getLatitude();

And then i pass the long and lat into the text, but this only gives me the last know location i guess?

Can anyone tell me how to get the current location?

Regards /Fred


回答1:


you need to create a LocationListener and pass it to the LocationManager like this: locationManager.requestLocationUpdates( locationManager.getBestProvider(fine, true), minTime, 0, listenerFine); You will get your lat/long updates from the listener in onLocationChanged()




回答2:


Please referred Below Link it may be Help You Get user current position with gps/network android MapView or http://www.vogella.de/articles/AndroidLocationAPI/article.html



来源:https://stackoverflow.com/questions/9880410/get-current-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!