【发布时间】:2017-03-03 11:00:05
【问题描述】:
我是第一次使用 googleMap,所以请帮助我。我想在打开应用程序时在地图上显示用户位置。当用户已经打开 gps 时,我已经这样做了。
LocationManager locationManagerCt = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
locationCt = locationManagerCt
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
LatLng latLng=new LatLng(locationCt.getLatitude(), locationCt.getLongitude());
MarkerOptions marker = new MarkerOptions().position(latLng).title("Current Location").snippet("Discription");
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
// Moving Camera to a Location with animation
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng).zoom(15).build();
HomeActivity.mGoogleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
HomeActivity.mGoogleMap.addMarker(marker);
当 gps 关闭时。打开 Gps 后,我尝试做同样的事情。 我从这里打开 gps: https://stackoverflow.com/a/33555732/3393578
用户开启gps后
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1000) {
if(resultCode == Activity.RESULT_OK){
//after user press ok button on GPS popup
/*I've apply same code above but unable to get location
its give me error on Location (nullpointer) */
} if (resultCode == Activity.RESULT_CANCELED) {
}
}
}
打开 GPS 后如何在几秒钟内获取位置。 我不想刷新活动。
谢谢!
【问题讨论】:
标签: android google-maps location