您好我有这个问题谷歌地图v2显示这么多标记我只想要标记与我的确切位置。我该如何删除它?我的猜测是,它无法真正确定我的确切位置?这是我的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// show error dialog if GoolglePlayServices not available
if (!isGooglePlayServicesAvailable()) {
finish();
}
setContentView(R.layout.main);
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.googleMap);
googleMap = supportMapFragment.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);
}
@Override
public void onLocationChanged(Location location) {
Button btnOurLocation = (Button) findViewById(R.id.latlongLocation);
// TextView locationTv = (TextView) findViewById(R.id.latlongLocation);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// locationTv.setText("Latitude:" + latitude + ", Longitude:" +
// longitude);
try {
geocoder = new Geocoder(StopItActivity.this, Locale.ENGLISH);
addresses = geocoder.getFromLocation(latitude, longitude, 1);
StringBuilder str = new StringBuilder();
// Address returnAddress = addresses.get(0);
address = addresses.get(0).getAddressLine(0);
// String localityString = returnAddress.getLocality();
// String city = returnAddress.getCountryName();
// String region_code = returnAddress.getCountryCode();
// String zipcode = returnAddress.getPostalCode();
// str.append(address + "");
// str.append(localityString + "");
// str.append(city + "" + region_code + "");
// str.append(zipcode + "");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("tag", e.getMessage());
}
btnOurLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), address,
Toast.LENGTH_SHORT).show();
}
});
}
然后这是输出
答案 0 :(得分:0)
我认为你应该在添加新标记之前删除旧标记。在OnLocationChanged(位置位置)回调中添加标记之前添加以下代码行。
googleMap.clear()