Android 谷歌地图只显示了一个标记
我有下一个问题,我试图在谷歌地图中显示一些标记,但只显示第一个标记,而不显示其他标记。它不抛出任何异常,只显示第一个标记(电话位置)Android 谷歌地图只显示了一个标记,android,google-maps,Android,Google Maps,我有下一个问题,我试图在谷歌地图中显示一些标记,但只显示第一个标记,而不显示其他标记。它不抛出任何异常,只显示第一个标记(电话位置) @覆盖 CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){ context=getActivity().getApplicationContext(); v=充气机。充气(R.布局图。碎片图,容器,假); Bundle b=getArguments(); 接收外部数据(b); 初始化(getActivity()); mMapView=(
@覆盖
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
context=getActivity().getApplicationContext();
v=充气机。充气(R.布局图。碎片图,容器,假);
Bundle b=getArguments();
接收外部数据(b);
初始化(getActivity());
mMapView=(MapView)v.findviewbyd(R.id.map);
mMapView.onCreate(mBundle);
需要(v);
返回v;
}
@凌驾
公共事务主任(活动){
超级转速计(活动);
试一试{
侦听器=(FragmentsListener)活动;
}catch(ClassCastException e){}
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mBundle=savedInstanceState;
}
需要专用void setupMapiFneed(视图膨胀视图){
如果(mMap==null){
mMap=((MapView)inflatedView.findviewbyd(R.id.map)).getMap();
如果(mMap!=null){
setUpMap();
}
}
}
私有void setUpMap(){
GPSPoint point=新的GPSPoint(上下文);
LatLng LatLng=point.getCurrentPositionLatLng();
MarkerOptions phoneMarker=新的MarkerOptions().position(latLng.title)(“Marker”);
mMap.addMarker(phoneMarker);
图标(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
CameraPosition CameraPosition=新建CameraPosition.Builder().target(latLng.zoom)(20.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
添加设备标记(连接的设备);
}
@凌驾
恢复时公开作废(){
super.onResume();
mMapView.onResume();
}
@凌驾
公共无效暂停(){
super.onPause();
mMapView.onPause();
}
@凌驾
公共空间{
mMapView.onDestroy();
super.ondestory();
}
私有无效接收外部数据(捆绑包b){
connectedDevices=b.getParcelableArrayList(bundleSkey.BLUETOOTH\u设备\u阵列);
}
私有void getDevicePosition(蓝牙设备){
listener.getDeviceLocation(bDevice);
}
专用void addDeviceMarkers(ArrayList列表){
如果(!list.isEmpty()){
BluetoothDevice=list.get(0);
获取设备位置(设备);
}
}
公共空白添加标记(板条位置){
MarkerOptions deviceMarker=新的MarkerOptions().位置(pos).标题(“设备”);
mMap.addMarker(设备标记器);
}
有人知道解决办法??有人知道如何为设备位置事件编写侦听器吗?您只需使用
mMap.addMarker()
所需的标记数即可。如果只使用一次,就像在setUpMap()
中一样,您将只看到一个标记。
不要忘记更改每个标记的
标记选项
属性 在setUpMap()
方法上,只添加一个标记。它只运行一次。不是很多。我解决了它,我添加了更多的点,它显示了它们。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = getActivity().getApplicationContext();
v = inflater.inflate(R.layout.fragment_map, container, false);
Bundle b = getArguments();
receiveExtraData(b);
MapsInitializer.initialize(getActivity());
mMapView = (MapView) v.findViewById(R.id.map);
mMapView.onCreate(mBundle);
setUpMapIfNeeded(v);
return v;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (FragmentsListener) activity;
} catch (ClassCastException e) {}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBundle = savedInstanceState;
}
private void setUpMapIfNeeded(View inflatedView) {
if (mMap == null) {
mMap = ((MapView) inflatedView.findViewById(R.id.map)).getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
GPSPoint point = new GPSPoint(context);
LatLng latLng = point.getCurrentPositionLatLng();
MarkerOptions phoneMarker = new MarkerOptions().position(latLng).title("Marker");
mMap.addMarker(phoneMarker);
phoneMarker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(20).build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
addDevicesMarkers(connectedDevices);
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
public void onDestroy() {
mMapView.onDestroy();
super.onDestroy();
}
private void receiveExtraData(Bundle b){
connectedDevices = b.getParcelableArrayList(BundlesKeys.BLUETOOTH_DEVICES_ARRAY);
}
private void getDevicePosition(BluetoothDevice bDevice){
listener.getDeviceLocation(bDevice);
}
private void addDevicesMarkers(ArrayList<BluetoothDevice> list){
if (!list.isEmpty()){
BluetoothDevice device = list.get(0);
getDevicePosition(device);
}
}
public void addMarker(LatLng pos){
MarkerOptions deviceMarker = new MarkerOptions().position(pos).title("Device");
mMap.addMarker(deviceMarker);
}