我正在创建一个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。请帮助! !
蓝点的外观取决于你的设备是否能够本地化。
请确保您打开了GPS并在设置应用程序的"我的位置"部分启用了相关设置:"使用无线网络"one_answers"使用GPS卫星"。