React Native 地图自定义标记不起作用

问题描述 投票:0回答:1

如何在React Native地图中自定义地图标记?当我单击标记时,它什么也不显示。它不显示标注组件。而且,它不允许覆盖标记样式,并且它拒绝按照我的意愿覆盖宽度和高度。

          <Marker key={city.id} coordinate={{ latitude: city.latitude, longitude: city.longitude }}><View style={{width:120 , height: 30}}>Hello</View></Marker>     

查看反应本机地图标记宽度和高度样式并未覆盖

android react-native google-maps
1个回答
0
投票

尝试使用

Callout

import  { Callout, Marker } from "react-native-maps"
const customeIcon = require("path_to_icon");

const [selectedCity, setSelectedCity] = React.useState();

<Marker
  key={city.id}
  coordinate={{ latitude: city.latitude, longitude: city.longitude }}
  image={customeIcon}
  onPress={() => setSelectedCity(city)}
>
  <Callout tooltip>
    <TouchableHighlight><Text>Hello</Text></TouchableHighlight>
  </Callout>
</Marker>

{ selectedCity && <YourCityDetailsComponent /> }
© www.soinside.com 2019 - 2024. All rights reserved.