0
map with default marker that is never set地图显示的默认标记,但它永远不会设置
在地图的中间有一个标志,它总是在这个位置所示,当我开始用它的地图片段的活性。但我从来没有设置这个标记......有人知道这是为什么,也许我怎么可以删除这个标记?
这里是我的代码:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
int permissionCheck = ContextCompat.checkSelfPermission(MapsActivity.this,
android.Manifest.permission.ACCESS_FINE_LOCATION);
if(permissionCheck == PackageManager.PERMISSION_GRANTED){
getCurrentLocation();
onSearch();
}else if(permissionCheck == PackageManager.PERMISSION_DENIED){
onSearch();
}
}
//gets current location of the user.
public void getCurrentLocation() {
double lat = 0;
double lng = 0;
try {
mMap.setMyLocationEnabled(true); //allows query of current location.
}catch(SecurityException e){
e.printStackTrace();
}
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Geocoder geocoderGetAddress = new Geocoder(MapsActivity.this);
try{
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(location!=null) {
lat = location.getLatitude();
lng = location.getLongitude();
}
}catch(SecurityException e){
e.printStackTrace();
}
//the rest of this method gets the address from the geocoder, so that it can be displayed as a String on the marker info window.
String displayAddress ="";
try {
List<Address> currAddress = geocoderGetAddress.getFromLocation(lat, lng, 1);
if(currAddress.size() >0){
for(int i=0; i<currAddress.get(0).getMaxAddressLineIndex();i++){
displayAddress += currAddress.get(0).getAddressLine(i) +"\n";
}
}
}catch (IOException e){
e.printStackTrace();
}
mMap.addMarker(new MarkerOptions().position(new LatLng(lat,lng)).title(myLoc).snippet(displayAddress));
LatLng myLatLng = new LatLng(lat, lng);
mMap.animateCamera(CameraUpdateFactory.newLatLng(myLatLng));
initAcceptButton();
}
谢谢!
你用'mMap.addMarker'加入它,它以动画与'mMap.animateCamera' – zgc7009
不,我只添加此标记的中心,当我得到智能手机的当前位置。 –
这并不能改变你添加它的事实,你目前的经纬度还没有被修正。 – zgc7009