获取当前坐标 [英] Get current coordinates

查看:187
本文介绍了获取当前坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应该在SMS中发送坐标的应用程序,但是我在理解如何获取坐标方面一直有些挣扎.

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.

此刻我正在使用

  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?

问候 /弗雷德

推荐答案

您需要创建一个LocationListener并将其传递给LocationManager,如下所示:locationManager.requestLocationUpdates( locationManager.getBestProvider(fine, true), minTime, 0, listenerFine); 您将在onLocationChanged()

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()

这篇关于获取当前坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆