嘗試使用此代碼
GPSTracker gps;
gps = new GPSTracker(SearchLocation.this);
if (gps.canGetLocation()) {
usersearchlat = gps.getLatitude();
usersearchlong = gps.getLongitude();
} else {
gps.showSettingsAlert();
}
,或者您可以使用其他一些代碼,緯度,經度和使用此代碼 -
mMapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getApplicationContext()
.getApplicationContext());
googleMap = mMapView.getMap();
googleMap.setMyLocationEnabled(true);
googleMap.setMapType(googleMap.MAP_TYPE_HYBRID);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setRotateGesturesEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
googleMap.addMarker(marker);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(usersearchlat, usersearchlong))
.zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
添加這樣的一些perditions: -
<uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION">
</uses-permission>
<uses-permission
android:name="android.permisssion.ACCESS_COARSE_LOCATION"></uses-
permission>
<uses-permission android:name="android.permisssion.INTERNET"/>
Access_Coarse_location。
你是指「半英里以上」 – Neji