指定的孩子已经有一个父母。您必须先对孩子的父母调用removeView()

时间:2019-11-11 08:25:25

标签: react-native react-native-android

我想在MapView中使用Marker。每次要加载时,都会遇到此错误。任何帮助,将不胜感激。

我有一些解决方案。但是我的情况没有锻炼。

public class Cat implements Animal {
  public void makeSound() {
    System.out.println("Meow");
  }
}

我希望没有错误地呈现标记。

这是我使用的依赖项:

import React, { Component } from "react";

import MapView, { Polyline } from "react-native-maps";

<View style={StyleSheet.absoluteFillObject}>
  <MapView
    showsUserLocation //to show user current location when given access
    loadingEnabled //to show loading while map loading
    style={styles.map}
    initialRegion={{
      // latitude : 27.6937681,
      latitude,
      // longitude : 85.3216398,
      longitude,
      latitudeDelta: 0.0922,
      longitudeDelta: 0.0421
    }}
  >
    <>
      {locations &&
        locations.map((location, index) => {
          const {
            coords: { latitude, longitude }
          } = location;
          return (
            <Marker
              key={index}
              coordinate={{ latitude, longitude }}
              // onPress={this.onMarkerPress(location)}
            />
          );
        })}

      <Polyline strokeWidth={2} strokeColor="red" coordinates={coords} />
    </>
  </MapView>
</View>

1 个答案:

答案 0 :(得分:0)

我让它像这样工作:

<View style={StyleSheet.absoluteFillObject}>
                <MapView 
                    showsUserLocation //to show user current location when given access
                    loadingEnabled //to show loading while map loading
                    style={styles.map}
                    initialRegion={{
                        latitude,
                        longitude,
                        latitudeDelta : 0.0922,
                        longitudeDelta: 0.0421
                    }}
                >

                    <Polyline
                        strokeWidth={2}
                        strokeColor="red"
                        coordinates={coords}
                    />  

                    {

                        locations && locations.map((location, index) => {
                            const {
                                coords: { latitude, longitude }
                            } = location;

                            return (
                                <MapView.Marker
                                    key={index}
                                    coordinate={{ latitude, longitude }}
                                    title={location.name}
                                    description={location.address}

                                />
                            )
                        })
                    }

                </MapView>
            </View>

快乐分享和编码。