android地图总是返回相同的位置

时间:2014-11-03 17:21:19

标签: google-maps android-mapview android-maps-v2

我正在尝试将当前位置从我开发的Android应用程序发送到服务器,但提供程序始终发送相同的位置,而不是我可以看到点标记的位置。

我请求这样的位置更新:

    // Getting LocationManager object from System Service LOCATION_SERVICE.
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    // Creating a criteria object to retrieve provider.
    Criteria criteria = new Criteria();

    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setBearingRequired(true);

    // Getting the name of the best provider.
    String provider = locationManager.getBestProvider(criteria, true);
    locationManager.requestLocationUpdates(provider, 2, 2, this);

我得到了拉特和那么久:

public void onLocationChanged(Location location) {

    Location currentLocation;
    Location nextLocation;

    if (MapVisible == true) {

        // Creating a LatLng object for the current location.
        latitude = location.getLatitude(); <--------here
        longitude = location.getLongitude(); <--------here   

        ...

但是服务器总是会收到相同的位置。关于这个问题的任何提示? 感谢

1 个答案:

答案 0 :(得分:0)

这有很多原因。也许是因为你已经连接到一个Wi-Fi网络并且你的GPS关闭了,所以你的手机只能从你的IP地址获取位置,IP地址的位置通常是一样的。

此外,您使用的是criterialocationManager.getBestProvider();,它会根据您的条件返回相同的提供商。忽略其他提供商提供的与您的标准不符的其他位置。

如果您想知道为什么您的位置与蓝点标记不同,您可以尝试从Android位置API切换到Play服务位置API,它更准确,更简单。更多信息:https://developer.android.com/google/play-services/location.html