在尝试long..am面向问题获取用户当前的GPS定位定位后。
所以,我想如果我们能用预装的Google地图应用程序的Current Location修复程序编程地得到一个定位修复吗?
如果我能够获取background..is中的协调位置,这可能吗?
那么,是否有可能通过使用意图或广播接收器来获取当前位置的协调?(假设地图应用程序正在广播它)。?)
更新2 :终于.我让它开始工作了。
更新:我以前的代码是这里(PasteBin链接)
欢迎任何建议..。谢谢..
发布于 2013-02-04 19:44:23
好的,密码破解器,下面是我如何实现我的位置取取器:
// the listener to listen to the locations
private LocationListener listener = null;
// a location manager
private LocationManager lm = null;
// locations instances to GPS and NETWORk
private Location myLocationGPS, myLocationNetwork;
// instantiates fields
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
myLocationNetwork = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
myLocationGPS = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
listener = new myLocationListener();
// the listener that gonna notify the activity about location changes
public class myLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// "location" is the RECEIVED locations and its here that you should proccess it
// check if the incoming position has been received from GPS or network
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
lm.removeUpdates(this);
} else {
lm.removeUpdates(listener);
}
}
@Override
public void onProviderDisabled(String provider) {
lm.removeUpdates(this);
lm.removeUpdates(listener);
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}正如你所看到的,没有那么多的诡计。在实例化侦听器时,您应该会看到Android设备顶部的GPS图标。此外,每当您的位置发生变化(即您使用设备行走时),将调用OnLocationChanged方法。
此外,有趣的是,如果你只想得到你的位置,有几种方法可以做到这一点,所有以不同的返回速度和不同的声音。请检查GoogleGLM (对http://www.google.com/glm/mmap的请求,该请求返回与您的位置相同的json编码条纹)服务、三角剖分和网络位置。在上面的片段中,我向您展示了如何通过GPS和网络获取位置。希望这会有帮助..。:)
发布于 2013-02-04 19:27:31
您可以使用被动位置提供程序,但这并不意味着它将从GoogleMaps获取位置。此外,为了接收更新,应该运行GoogleMaps。要从GoogleMaps接收位置更新,还必须拥有ACCES_FINE_LOCATION的权限。此外,您不能启动GoogleMaps并强迫它在没有用户交互的情况下更新位置。如果您需要精确的用户位置,那么除了使用GPS_PROVIDER没有其他方法。
提供者
另外,您可能希望阅读http://developer.android.com/guide/topics/location/strategies.html http://developerlife.com/tutorials/?p=1375。
https://stackoverflow.com/questions/14693823
复制相似问题