[英]How to Zoom and get latitude and longitude from mMap.setMyLocationEnabled(true) in Google Map (Android)
I was setting mMap.setMyLocationEnabled(true)
and I am successfully getting my current location but... 我正在设置
mMap.setMyLocationEnabled(true)
并且成功获取了当前位置,但是...
Not able to zoom to that position. 无法缩放到该位置。
Not able to get lat and lng from that position 无法从该位置获取经纬度
From getting latitude and longitude I am using below code but it gives me null
. 从得到纬度和经度,我正在使用下面的代码,但它给我
null
。 I am calling below method from onMapReady(Google Map)
and passing google map object. 我从
onMapReady(Google Map)
调用下面的方法并传递google map对象。
private void goToCurrentLocation(GoogleMap map) {
Log.d("Tag", "inside");
Location loc = map.getMyLocation();
if (loc != null) {
LatLng point = new LatLng(loc.getLatitude(), loc.getLongitude());
Log.d("Tag=", "latlng=" + point);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(point, 15));
}
}
Is there any alternative to getting latitude and longitude as getMyLocation
deprecated? getMyLocation
弃用getMyLocation
还有其他方法可以获取纬度和经度吗?
use link provided in the answer to get current location and then zoom over that location using below code: 使用答案中提供的链接获取当前位置,然后使用以下代码放大该位置:
latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
mGoogleMap.animateCamera(cameraUpdate);
http://blog.teamtreehouse.com/beginners-guide-location-android http://blog.teamtreehouse.com/beginners-guide-location-android
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.