Java 谷歌地图Android API在切换楼层时删除标记
我正在做一个需要室内地图的Android应用程序项目。我使用的位置在谷歌地图上有楼层。我使用谷歌地图Android API。我在显示的初始标高上设置了标记。切换楼层时,如何删除/隐藏这些标记并替换为新标记? 以下是我的java代码:Java 谷歌地图Android API在切换楼层时删除标记,java,android,google-maps,Java,Android,Google Maps,我正在做一个需要室内地图的Android应用程序项目。我使用的位置在谷歌地图上有楼层。我使用谷歌地图Android API。我在显示的初始标高上设置了标记。切换楼层时,如何删除/隐藏这些标记并替换为新标记? 以下是我的java代码: package com.me.maps; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import com.google.android.gms.maps.C
package com.me.maps;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Milwaukee, Wisconsin.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng mpm = new LatLng(43.0408468, -87.921474);
LatLng planetarium = new LatLng(43.040622,-87.920798);
LatLng theater = new LatLng(43.040497,-87.920640);
LatLng marketplace = new LatLng(43.040779,-87.921717);
mMap.addMarker(new MarkerOptions().position(mpm).title("Milwaukee Public Museum"));
mMap.addMarker(new MarkerOptions().position(planetarium).title("The Daniel M. Soref National Geographic Planetarium"));
mMap.addMarker(new MarkerOptions().position(theater).title("The Daniel M. Soref National Geographic Theater"));
mMap.addMarker(new MarkerOptions().position(marketplace).title("Museum Marketplace"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mpm, 18));
}
}
使用此代码用于更改标记图标
使用此代码更改标记图标。当您切换楼层时,您的应用程序应清除地图上已有的标记。使用google map实例的.clear()方法,然后仅添加与该楼层相关的标记 有关此方法的文档,请访问:
希望能有所帮助。当您切换楼层时,您的应用程序应该清除地图上已有的标记。使用google map实例的.clear()方法,然后仅添加与该楼层相关的标记 有关此方法的文档,请访问:
希望有帮助。谢谢您的回复。我不知道这是怎么回事。我将它添加到onMapReady()中,它显示了错误。是否有某种方法来实现这一点?是否需要将其附加到楼层选择器按钮?单击楼层选择器按钮时,只需使用@here、
markerOptions.clear()清除创建的标记即可。谢谢您的回复。我不知道这是怎么回事。我将它添加到onMapReady()中,它显示了错误。是否有某种方法来实现这一点?是否需要将其附加到楼层选择器按钮?单击楼层选择器按钮时,只需使用@here、markerOptions.clear()清除创建的标记。
我很难找到将.clear()附加到的位置。我正在查看文档,对楼层选择器的唯一引用是:setIndoorLevelPickerEnabled(true);他们是事件监听器还是我需要添加到代码中的东西?我不知道该去哪里找。我没有看到任何关于如何在单击这些特定按钮时添加任何内容的参考。我很难找到将.clear()附加到的位置。我正在查看文档,对楼层选择器的唯一引用是:setIndoorLevelPickerEnabled(true);他们是事件监听器还是我需要添加到代码中的东西?我不知道该去哪里找。我看不到任何关于如何在点击这些特定按钮时添加任何内容的参考。
//Place current location marker
latitude = location.getLatitude();
longitude = location.getLongitude();
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.doctor);
markerOptions.icon(icon);
mCurrLocationMarker = mMap.addMarker(markerOptions);
//move map camera
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));