【发布时间】:2016-09-23 15:05:39
【问题描述】:
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将其动画化到中心 -
不,我只是在获得智能手机的当前位置时添加这个标记。
-
这并没有改变您添加它的位置,您当前的纬度/经度尚未修复。
标签: android dictionary marker