Android 显示当前位置,但在一侧显示pin,在另一侧显示蓝点
我尝试了Daniel Nugent回答的这个解决方案 但这里有一个bug。首先,当您找到Pin并且(蓝点)保持在同一位置时,但当您更改位置时,只有蓝点更改位置Pin保持在旧位置 只有一次通过GoogleAPI输入覆盖方法Android 显示当前位置,但在一侧显示pin,在另一侧显示蓝点,android,google-maps,google-maps-android-api-2,Android,Google Maps,Google Maps Android Api 2,我尝试了Daniel Nugent回答的这个解决方案 但这里有一个bug。首先,当您找到Pin并且(蓝点)保持在同一位置时,但当您更改位置时,只有蓝点更改位置Pin保持在旧位置 只有一次通过GoogleAPI输入覆盖方法 @Override public void onLocationChanged(Location location){} 我更新了原始答案,因为这一部分引起了太多的混乱 为了在收到第一个位置更新后保持位置更新,请在onLocationChanged()覆盖中删除对remove
@Override
public void onLocationChanged(Location location){}
我更新了原始答案,因为这一部分引起了太多的混乱 为了在收到第一个位置更新后保持位置更新,请在
onLocationChanged()
覆盖中删除对removelocationUpdate()
的调用:
@Override
public void onLocationChanged(Location location)
{
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
//move map camera
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,11));
}
你能发布你的
onLocationChanged
方法吗?丹尼尔的回答删除了onLocationChanged()
中的位置更新。请确保将该请求移到其他位置以接收多个位置更新。这里是@antonioAs@Sammy建议,删除这些行:if(mGoogleApiClient!=null){LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,this);}
谢谢大家:)