[OK]を、より良いソリューションのこの質問に従ってくださいよ、私はhttps://github.com/airbnb/react-native-maps/issues/488からこの答えを得ました。
アイデアはそうのようなMapView
コンポーネントにonPress
イベントを追加することです:
<MapView onPress={ this.mapPressed }>
次に、(double配列が目的であり、それは機能が動作する方法です)あなたが行うことができますgeojson-js-utilsを使用して:
import { pointInPolygon } from 'geojson-utils';
mapPressed(event) {
const pointCoords = [event.nativeEvent.coordinate.longitude,
event.nativeEvent.coordinate.latitude];
const polygonCoords = [ [lngA, latA], [lngB, latB] ... etc... ];
const inPolygon = pointInPolygon(
{ 'type': 'Point', 'coordinates': pointCoords },
{ 'type': 'Polygon', 'coordinates': [plotCoords] }
);
if (inPolygon) {
// do something
}
}
ありがとうございます!私はそれを試してみましょう。ユーザーがマーカーの正確な座標に触れる前にマーカーを使用しないでください。 –
さて、はい、しかし、私はユーザーが触れるように私は妥当なサイズを指定し、実際には何も視覚的にレンダリングしないカスタムマーカーを使用しました。 – Felipe92
あなたの答えは今のところ正しいと書いてあります。それは動作します:-) ポリゴンのサイズに応じてマーカーのサイズを設定する良い方法はありますか、それとも静的なサイズですか? –