指定的 child 已经有一个 parent。您必须先在 child 的 parent 上调用 removeView() 以响应本机
The specified child already has a parent. You must call removeView() on the child's parent first react native
我想在 MapView 中使用 Marker。每次我想加载时都会遇到这个错误。任何帮助,将不胜感激。
我得到了一些解决方案。但是我的情况没有锻炼。
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>
我想无错误地渲染标记。
这是我使用的依赖项:
"dependencies": {
"native-base": "^2.13.8",
"react": "16.9.0",
"react-native": "0.61.2",
"react-native-maps": "git+https://git@github.com/react-native-community/react-native-maps.git"
}```
我是这样工作的:
<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>
祝分享和编码愉快。
我想在 MapView 中使用 Marker。每次我想加载时都会遇到这个错误。任何帮助,将不胜感激。
我得到了一些解决方案。但是我的情况没有锻炼。
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>
我想无错误地渲染标记。
这是我使用的依赖项:
"dependencies": {
"native-base": "^2.13.8",
"react": "16.9.0",
"react-native": "0.61.2",
"react-native-maps": "git+https://git@github.com/react-native-community/react-native-maps.git"
}```
我是这样工作的:
<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>
祝分享和编码愉快。