2014-11-03 51 views
0

我想从我开发的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); 

,我得到lat和长这样:

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 

     ... 

但是服务器总是收到相同的位置。有关该问题的任何提示? 谢谢

回答

0

有很多原因。也许是因为你连接到了Wi-Fi网络,而你的GPS是关闭的,所以你的手机只能从你的IP地址获得位置,IP地址的位置通常是相同的。

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

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