【问题标题】:Blue bubble of current location in google maps not showing during first attempt in android谷歌地图中当前位置的蓝色气泡在 Android 的第一次尝试中未显示
【发布时间】:2014-07-16 10:10:38
【问题描述】:

我正在创建一个具有谷歌地图的 android 应用程序。我想将当前位置显示为带有当前位置按钮的默认蓝点。蓝点和按钮在较新版本的 android 上显示良好。但在较旧的设备,第一次运行应用程序时未显示,但第二次尝试后很好。我尝试使用 android 支持库但无济于事。

我使用的代码如下所示:

public void getcurrentlocation()
    {
         locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        // Creating a criteria object to retrieve provider
        Criteria criteria = new Criteria();
        // Getting the name of the best provider
        String provider = locationManager.getBestProvider(criteria, true);

        Location location = locationManager.getLastKnownLocation(provider);
        if(location!=null)
        {
            current_latitude = location.getLatitude();
           current_longitude = location.getLongitude();
           initialiseMap();
        }
        locationManager.requestLocationUpdates(provider, 20000, 0, this);

        }
public void initialiseMap()
    {
        if (googleMap == null) {
             googleMap = ( (SupportMapFragment) getSupportFragmentManager().findFragmentById(
                        R.id.map)).getMap();


       }
        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
        else
        {
        googleMap.setMyLocationEnabled(true);
        googleMap.getUiSettings().setMyLocationButtonEnabled(true);
        googleMap.getUiSettings().setCompassEnabled(true);
//          UiSettings uiSettings = googleMap.getUiSettings();
//          uiSettings.setMyLocationButtonEnabled(true);



            }
            //locationManager.requestLocationUpdates(provider, 20000, 0, this);
        LatLng latLng = new LatLng(current_latitude, current_longitude);
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

        // Zoom in the Google Map
        //googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12f));
        new RetrieveStoreDetails().execute();
        }

有没有一种解决方法可以在旧版本(2.6)的android上从头开始显示蓝点。请帮助!!

【问题讨论】:

    标签: java android eclipse google-maps


    【解决方案1】:

    蓝点外观取决于您的设备是否能够自行定位。

    确保打开 GPS 并在“设置”应用的“我的位置”部分启用相关设置:“使用无线网络”和“使用 GPS 卫星”。

    【讨论】:

    • 使用无线网络、使用 GPS 卫星和使用传感器辅助在设置中打开。我仍然遇到问题。还有其他建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    相关资源
    最近更新 更多