如何从默认城市启动谷歌地图(我有lat,lng和zoom)。现在,当我开始绘制地图时,首先我看到整个世界,然后将地图激活到我的位置。
答案 0 :(得分:2)
谷歌地图Android API允许您通过修改地图相机来更改用户的地图视点。
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 15);
答案 1 :(得分:0)
使用Google地图moveCamera(CameraUpdate update)
来避免动画并指示您的位置
private void setUpMap() {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(19.111990, 72.834034)).title("Marker"));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(19.111990, 72.834034))
.zoom(15).build();
mMap.moveCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
}
答案 2 :(得分:0)
试试这个:
private LocationManager locationManager;
private Location location;
private Criteria criteria;
this.locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
criteria = new Criteria();
location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, true));
if (location != null) {
// add marker on map at current location
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
googleMap.addMarker(new MarkerOptions().position(latLng).title("I am here"));
// Creating a LatLng object for the current location
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// to show current location on opening map
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
}