Abd*_*du4 12 android google-maps react-native react-native-maps
我正在使用react-native-maps但是我遇到了一个问题,经过大量谷歌搜索没有回答让我在这里问.我正在尝试使用自定义标记作为地图中的标记,如下图所示

当我搜索时,我发现需要使用Custom Marker来完成制作者的设计,然后我创建了一个Custom Marker组件
import React, { Component } from "react";
import { View } from "react-native";
import {
Text,
Left,
Right,
Thumbnail,
} from "native-base";
const defaultEmployeeLogo = require("../../../assets/defualtEmployee.png");
class CustomMarker extends Component {
render() {
return (
<View style={{ flexDirection: 'row', width: 140, height: 60,
borderRadius: 70, backgroundColor: 'orange' }}>
<Left>
<Thumbnail source={defaultEmployeeLogo} />
</Left>
<Right>
<Text style={{
color: '#fef',
fontSize: 13,
paddingBottom: 2,
fontFamily: 'Roboto',
alignItems: 'center',
paddingRight: 10
}}>Mohammad</Text>
</Right></View >);
}
}
export default CustomMarker;
Run Code Online (Sandbox Code Playgroud)当我单独使用CustomMarker.js类时,它工作正常,它显示图像,但当我用它作为标记自定义视图时,它不显示图像
我不知道为什么它无法在android中使用Custom Marker渲染图像.这是我的代码,我正在使用地图,标记和自定义标记类
return (
<View style={styles.map_container}>
<MapView
style={styles.map}
customMapStyle={customrMapStyle}
region={{
latitude: this.state.region.latitude,
longitude: this.state.region.longitude,
latitudeDelta: 0.4,
longitudeDelta: 0.41,
}} >
{
coordinationData.map(function (marker, i) {
let lat = marker.latLang.latitude;
let lang = marker.latLang.longitude;
<MapView.Marker
key={i}
coordinate={
{
latitude: lat,
longitude: lang,
latitudeDelta: 0.4,
longitudeDelta: 0.41
}
}
title={marker.title}
description={marker.description}
>
<CustomMarker />
</MapView.Marker>
})}
</MapView>
</View>
Run Code Online (Sandbox Code Playgroud)
任何形式的帮助将不胜感激.
使用SVG此https://github.com/react-native-community/react-native-svg
<Marker
coordinate={{
longitude: lang,
latitude: lat,
}}
>
<View style={{
flexDirection: 'row', width: 100, height: 30,
backgroundColor: 'orange'
}}>
<Svg
width={40} height={30}>
<Image
href={url}
width={40}
height={30}
/>
</Svg>
<View
style={{
flexDirection: 'column'
}}
>
<Text
style={{
marginLeft: 2,
fontSize: 9,
color: '#ffffff',
fontWeight: 'bold',
textDecorationLine: 'underline'
}}
>{marker.title}</Text>
<Text
style={{
marginLeft: 2,
fontSize: 9,
color: '#ffffff',
fontWeight: 'bold',
textDecorationLine: 'underline'
}}
>{marker.description}</Text>
</View>
</View>
</Marker>
Run Code Online (Sandbox Code Playgroud)
我的问题马上就解决了。
我希望你的问题会得到解决。
import React, {Component} from 'react';
import {ImageBackground, Text} from 'react-native';
import {Marker} from 'react-native-maps';
export default class CustomMarker extends Component {
state = {
initialRender: true
}
render() {
return (
<Marker
//...
>
<ImageBackground
source={require('../assets/cluster3_mobile.png')}>
// *** These lines are very important ***
onLoad={() => this.forceUpdate()}
onLayout={() => this.setState({initialRender: false})}
key={`${this.state.initialRender}`}
>
// **** This line is very very important ****
<Text style={{width: 0, height: 0}}>{Math.random()}</Text>
</ImageBackground>
</Marker>
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5878 次 |
| 最近记录: |