react-native-maps: It does not work onPress props in Circle
Hi, my component code
<MapView region={this.state.region}> <Circle center={this.state.region} onPress={()=>{ console.warn('xxxxxxxx!')}} radius={2000} /></MapView>
simple example, it does not work onPress in Circle bud move onPress in MapView and its ok
I require you to execute an event that returns latitude and longitude by tocuh in the circle marked on the map
react-native 0.43.4 react-native-maps 0.15.0
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 15
- Comments: 15
I solved my problem as follows:
First I installed geolib (https://github.com/manuelbieh/geolib) and I imported
import {getDistance} from 'geolib';I created the circles in my state and a control variable for the clicked circle
then I used the
MapViewonPressevent to retrieve the latitude and longitude clicked to compare with the latitudes and longitudes of my circles.The calculation is simple: If the difference distance between the two points is less than the radius of my circle inside the loop, it means that it was clicked. At this point, store the
_idof this circle in mystateto do whatever it takes.I know there’s a work-around, but I’m wondering if there is any plan to fix the issue?
Working from me… thanks!
Facing the same issue, any news on when Circle onPress will be fixed?
For anyone who wants a work around, you can use
And then
checkCoordsiterates through your circles and uses the Haversine formula to check whether the press is inside the circle.Explanation: https://en.wikipedia.org/wiki/Haversine_formula
Implementation: https://stackoverflow.com/questions/14560999/using-the-haversine-formula-in-javascript
Haversine is not perfect because it assumes the earth is a perfect sphere which introduces a whole bunch of problems but I’ve found it works fairly well. (And not triggering when tapping the edge of the circle isn’t too big a problem).
MapView.Circle onPressshould definitely be fixed though.I guess so… Do you have a good alternative? Everywhere I go I sadly go back to here.
The issue is 7 years old dudes… I don’t think the library is properly maintained anymore. It will probably not get fixed.
Bump… Why isn’t anyone answering on this?