问题
I am trying to render a button which I can use to redirect to another page within the description page (the pop-up-box if you select a marker) using AirBnb maps (using MapView.Markers
). I am not sure how to achieve this.
Currently my markers look as follow:
const markers = [{
longitude: 8.545592,
latitude: 47.366465,
description: "Bike 1",
title: "Bike 1"
},
{
longitude: 8.545892,
latitude: 47.366365,
description: "Bike 2",
title: "Bike 2"
}
];
Whenever I try to input JSX into a text, I get a NSMutableDictionary cannot be converted to NSString
error. (When I do this:
const markers = [{
longitude: 8.545592,
latitude: 47.366465,
description: <Text>Bike1</Text>, //"Bike 1", //<Text> Bike1 </Text>
title: "Bike 1"
},
{
longitude: 8.545892,
latitude: 47.366365,
description: "Bike 2",
title: "Bike 2"
}
];
回答1:
For more than just text, what you should do is define a custom Callout instead of using description
prop. For example:
<MapView.Marker
coordinate={{longitude: marker.longitude, latitude: marker.latitude}}
title={marker.title}
>
<MapView.Callout>
<View style={styles.callout}>
<Button title='Click Me!' onPress={() => console.log('Clicked')} />
</View>
</MapView.Callout>
</MapView.Marker>
来源:https://stackoverflow.com/questions/44475332/react-native-airbnb-maps-how-do-i-render-a-button-inside-the-airbnb-maps-pop-up