【发布时间】:2015-12-31 15:15:06
【问题描述】:
我正在使用 apiV2 在谷歌地图中显示一个带有精度圆盘的圆圈,以及一个以圆圈为中心的标记。
onLocationChanged 我正在删除现有的圆圈/标记。 onMapReady 我正在绘制新的圆圈/标记。
我试图在代码中的圆圈“之后”绘制标记。我试图在标记上调用 .showInfoWindow() ,但即便如此它仍然显示在圆圈后面。
这是我的代码(显然还没有完成):
public void onLocationChanged(Location location) {
newLatLng = new LatLng(location.getLatitude(), location.getLongitude());
//Circle management
if (myLocationCircle != null) {
myLocationCircle.remove();
}
circleOptions = new CircleOptions()
.center(newLatLng)
.radius(location.getAccuracy())
.strokeWidth(2)
.strokeColor(Color.BLUE)
.fillColor(Color.parseColor("#500084d3")); //Format are: #RRGGBB #AARRGGBB, where #AA is the transparency
//Marker management
if (myLocationMarker != null) {
myLocationMarker.remove();
}
markerOptions = new MarkerOptions()
.position(newLatLng)
.title("Hey, that's my position!");
onMapReady(mGoogleMap);
}
@Override
public void onMapReady(GoogleMap myGoogleMap) {
if (myGoogleMap == null) {
Toast.makeText(this.getApplicationContext(),"Sorry! Unable to initialize the map", Toast.LENGTH_LONG).show();
}
else {
mGoogleMap = myGoogleMap;
myGoogleMap.setMyLocationEnabled(true);
myGoogleMap.getUiSettings().setZoomControlsEnabled(true);
myGoogleMap.getUiSettings().setAllGesturesEnabled(true);
myGoogleMap.getUiSettings().setCompassEnabled(true);
myGoogleMap.getUiSettings().setMapToolbarEnabled(true);
myGoogleMap.setMyLocationEnabled(true);
myCurrentCameraPosition = myGoogleMap.getCameraPosition();
if ( newLatLng != null ) {
CameraPosition myNewCameraPosition = new CameraPosition(newLatLng, 15, myCurrentCameraPosition.tilt, myCurrentCameraPosition.bearing);
myGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(myNewCameraPosition));
if (circleOptions!=null){
//Draw blue circle around your position (setup of options done in onLocationChange())
myLocationCircle = myGoogleMap.addCircle(circleOptions);
}
if (markerOptions != null) {
//Draw a marker at your position (setup of options done in onLocationChange())
myLocationMarker = mGoogleMap.addMarker(markerOptions);
myLocationMarker.showInfoWindow();
}
}
}
}
【问题讨论】:
标签: android google-maps-markers google-maps-api-2