【发布时间】:2015-10-12 19:06:03
【问题描述】:
我有以下函数可以返回设备的当前位置:
void getCurrentLocation()
{
Location myLocation = map.getMyLocation();
if(myLocation!=null)
{
double dLatitude = myLocation.getLatitude();
double dLongitude = myLocation.getLongitude();
map.addMarker(new MarkerOptions().position(new LatLng(dLatitude, dLongitude))
.title("My Location").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(dLatitude, dLongitude), 8));
}
else
{
Toast.makeText(this, "Unable to fetch the current location", Toast.LENGTH_SHORT).show();
}
}
如您所见,这些方法与地图相关,它在 onMapReady() 函数中工作,但在它之外显示它无法识别。这是为什么?我必须添加哪些库?我这样声明地图:
private MapFragment map;
【问题讨论】:
标签: android google-maps google-maps-api-2