我已使用此代码查找当前位置
googleMap.setMyLocationEnabled(真);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
LatLng latlng = new LatLng(latitude, longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(10));
googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("Iam here!"));
我得到了诅咒。请帮帮我
答案 0 :(得分:0)
尝试这对我有用
Criteria criteria = new Criteria();
Location location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 20000, 0, Context here); // requesting
currentLocationLatLng = new LatLng(currentLatitude,
currentLongitude);
Marker location_present = map.addMarker(new MarkerOptions()
.position(currentLocationLatLng)
.title("you are here")
.snippet("")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker_)));// adding
// marker
// on
// map
并覆盖这些
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
// getting
// updated
// latlong
// values on
// changing
// of user's
// location
// TODO Auto-generated method stub
currentLatitude = location.getLatitude();
currentLongitude = location.getLongitude();
lat.add(currentLatitude);
lang.add(currentLongitude);
latlang.add(currentLocationLatLng);
Log.e("" + lat.toString() + "fsdf" + lang.toString(),
"" + latlang.toString());
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}