Android 删除默认用户';s位置图标
我正在使用Google Maps v2 for Android开发一个应用程序,我设法在用户的位置上放置了一个自定义图标,但我无法删除默认图标,因此它覆盖了我的自定义图标,如图所示: (就目前而言,它有那么大:p) 我的代码如下:Android 删除默认用户';s位置图标,android,google-maps-android-api-2,Android,Google Maps Android Api 2,我正在使用Google Maps v2 for Android开发一个应用程序,我设法在用户的位置上放置了一个自定义图标,但我无法删除默认图标,因此它覆盖了我的自定义图标,如图所示: (就目前而言,它有那么大:p) 我的代码如下: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
map.setOnMyLocationChangeListener(new OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
if (location == null)
return;
mPositionMarker = map.addMarker(new MarkerOptions()
.flat(true)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.logop1))
.anchor(0.5f, 1f)
.position(new LatLng(location.getLatitude(), location.getLongitude())));
}
});
}
因此:
1) 有没有办法删除用户当前位置的默认蓝点
2) 当我在“真实世界”中移动时,是否会更新用户位置(出于连接原因,我无法对其进行测试),或者我是否必须编写/重写一个方法来更新用户位置
提前感谢您将不得不停止使用
GoogleMap.setMyLocationEnabled
并编写更多代码,包括拥有自己的代码和添加圆圈
,以确保准确性
你必须自己去做。
-设置为falsegmaps.getUiSettings().setMyLocationButtonEnabled(false)代码>
- 创建自己的位置按钮
- 如果您得到当前位置,请在该位置上设置一个带有图标的标记
- 如果单击“位置”按钮,请移动相机并将其置于地图中心
这将删除蓝点谢谢joao2fast4u(lol)和ṁᾶƔƏň ツ. 我按照你的建议做了,我成功地做到了。由于我没有看到这个问题的任何具体答案,我在这里发布了我的解决方案:
package com.onsoftwares.ufvquest;
import android.location.Location;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapActivity extends ActionBarActivity implements LocationListener, GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener {
private GoogleMap map;
private Marker mPositionMarker;
private LocationClient mLocationClient;
private LocationRequest mLocationRequest;
private LatLng mLatLng;
private boolean mUpdatesRequested = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mLocationClient = new LocationClient(this, this, this);
mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the interval ceiling to one minute
mLocationRequest.setFastestInterval(1000);
// Note that location updates are off until the user turns them on
mUpdatesRequested = false;
}
@Override
protected void onStart() {
super.onStart();
mLocationClient.connect();
};
@Override
protected void onStop() {
if (mLocationClient.isConnected()) {
mLocationClient.removeLocationUpdates(this);
mLocationClient.disconnect();
}
super.onStop();
};
@Override
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
}
@Override
public void onConnected(Bundle arg0) {
mLocationClient.requestLocationUpdates(mLocationRequest, this);
}
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// Get the current location
Location currentLocation = mLocationClient.getLastLocation();
// Display the current location in the UI
if (currentLocation != null) {
LatLng currentLatLng = new LatLng (currentLocation.getLatitude(), currentLocation.getLongitude());
if (mPositionMarker == null) {
mPositionMarker = map.addMarker(new MarkerOptions()
.position(currentLatLng)
.title("Eu")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.male_user_marker)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15));
} else
mPositionMarker.setPosition(currentLatLng);
}
}
}
map.setMyLocationEnabled(true);删除行查看和以获取您的答案。感谢您的答案,它真的很有帮助:)