Android:获取纬度和经度

时间:2012-02-21 05:37:15

标签: android google-maps geolocation

是否可以获得Lat& Lng不去户外?我目前的情况是,用户必须在室外才能获得他们的位置,这也需要相当长的时间才能获得一个。我希望我的用户能够将他们的位置放在室内。

4 个答案:

答案 0 :(得分:0)

是的,这是可能的,在你的网络内门。所以你可以使用LocationManager.NETWORK_PROVIDER来获得GPS共同点。

请查看此answer

答案 1 :(得分:0)

这取决于您正在使用的GPS提供商,并且信号可用于修复位置,我认为您仅使用GPS提供商,因此它不在门口工作,也尝试使用网络提供商。

此外,使用上次已知位置,在gps修复位置时,最早有一个很好的博客来获取位置。

android-developers.blogspot.in/2011/06/deep-dive-into-location.html

答案 2 :(得分:0)

是的,有可能,请从以下代码中提示:

try {
            gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        } catch (Exception ex) {
        }
        try {
            network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
        }

        if (!gps_enabled && !network_enabled) {
             // show alert 
        }
        if (network_enabled) {
            locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener);
        }
        if (gps_enabled) {
            locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
        }

答案 3 :(得分:0)

    LocationManager locManager;   
    Location location;
 double lat;
 double lng;
    try {
                gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            } catch (Exception ex) {
            }
            try {
                network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            } catch (Exception ex) {
            }

            if (!gps_enabled && !network_enabled) {
                 // show alert 
            }
            if (network_enabled) {
                  locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);                
                locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,1000,1, locationListener);
                location = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
             lat = location.getLatitude();
             lng = location.getLongitude();
            }
            if (gps_enabled) {
                locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);              
                locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,1, locationListener);
                location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
             lat = location.getLatitude();
             lng = location.getLongitude();
            }
相关问题