如何在React Native地图中将地面叠加层和标记一起应用?

时间:2016-06-20 07:00:45

标签: react-native

如何在React Native map中一起应用地面叠加层和标记?

我希望在叠加层上方放置一些标记,并在地图上方显示叠加层。

1 个答案:

答案 0 :(得分:1)

react-native-maps项目是一个非常强大且活跃的社区解决方案,可以解决这个问题。

这是一个绘制多边形叠加层并在叠加层上放置标记的示例:

import React from 'react';
import {
  AppRegistry,
  View
} from 'react-native';

import MapView from 'react-native-maps';

class MyApp extends React.Component {
  render () {
    return (
      <MapView
        style={{flex:1}}
        initialRegion={{
          latitude: 40.758242,
          longitude: -73.848986,
          latitudeDelta: 0.001,
          longitudeDelta: 0.01,
        }}
      >
        <MapView.Polygon
          coordinates={[
            { latitude: 40.757966, longitude: -73.847704 },
            { latitude: 40.758421, longitude: -73.845129 },
            { latitude: 40.756869, longitude: -73.844227 },
            { latitude: 40.755471, longitude: -73.846266 }
          ]}
          fillColor="rgba(0,0,255,0.2)"
          strokeColor="orange"
          strokeWidth={2}
        />
        <MapView.Marker
          title="Citi Field"
          description="center field"
          coordinate={{ latitude: 40.757405, longitude: -73.845815 }}
          pinColor="blue"
        />
      </MapView>
    );
  }
}

AppRegistry.registerComponent('MyApp', () => MyApp);