android - 在 android 中快速和频繁的位置更新..?

标签 android multithreading performance maps

public void getUserLocation() {

    Location location;
    TextView lon = (TextView) findViewById(R.id.textView2);
    TextView lat = (TextView) findViewById(R.id.textView3);
    boolean GpsEnable = false, NetworkEnabled = false;
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);




    // String locationProvider = LocationManager.GPS_PROVIDER;

    GpsEnable = locationManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
    NetworkEnabled = locationManager
            .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    // locationManager.requestLocationUpdates(locationProvider,0,0,locationListner);

    if (!GpsEnable && !NetworkEnabled) {
        Toast.makeText(getBaseContext(), "No Provider Availabe",
                Toast.LENGTH_SHORT);

    } else {

        if (NetworkEnabled)
            Toast.makeText(getBaseContext(), "Network Provider Available",
                    Toast.LENGTH_SHORT);
        locationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, 0, 0, this);

        if (locationManager != null) {
            location = locationManager
                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            lon.setText("Latitude" + location.getLatitude());
            lat.setText("Longitude " + location.getLongitude());
        }

        if (GpsEnable) {

            locationManager.requestLocationUpdates(
                    LocationManager.GPS_PROVIDER, 0, 0, this);

            if (locationManager != null) {

                location = locationManager
                        .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                if (location != null) {
                    lon.setText("Latitude" + location.getLatitude());
                    lat.setText("Longitude " + location.getLongitude());

                }
            }
        }
    }
}

我已经完成了 GPS 和网络提供商。我想知道我们如何在谷歌地图中获得准确的当前位置?有没有什么方法或算法可以让我使用内部谷歌地图获得我所在位置的经度和纬度? 提前致谢

最佳答案

我已按照本教程进行 GoogleMap v2 的快速更新和初始设置

Initial Setup Here

Alternative for LocationUpdate

希望这可以帮助...:)

关于android - 在 android 中快速和频繁的位置更新..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20278683/

相关文章:

android - 检测ListView中的TextView是否被椭圆化

java - Paper.init 未被调用

asp.net - 为什么要在 ASP.NET 健康监控上使用 HTTP 模块,反之亦然?

c - Unix下最快的删除目录

java - 为什么PocketSphinx Android demo需要cygwin

android - 我想在 android 中的谷歌地图的街景 View 中添加 popover/overlay/hotspot

java - 显示 ProgressDialog 时暂停 Android 应用程序的主线程

c# - 任务并行库执行长时间运行的操作

java - 多线程访问synchronizedList

performance - 给 Perl 的 print 一个列表或一个连接的字符串是否更快?