简体   繁体   中英

How do I use a user's location to display information that is near them or in a radius within?

I'm building an app that has people request something, so a user should only receive requests that are near to them or within a certain radius. How do I achieve this on flutter?

You need to have real time data on coordinates of person/people who is fulfilling the request. And when a request is made by the user, fetch the user's current coordinates and based on that coordinate filter the coordinates of person/people fulfilling the request depending on the specifies radius

There's a formula to calculate the distance between two coordinates

Distance, d = 3963.0 * arccos[(sin(lat1) * sin(lat2)) + cos(lat1) * cos(lat2) * cos(long2 – long1)]

But to use the formula you need convert the latitude and longitude values from decimal degrees to radians. For this divide the values of longitude and latitude of both the points by 180/pi. The value of pi is 22/7. The value of 180/pi is approximately 57.29577951. If we want to calculate the distance between two places in miles, use the value 3, 963, which is the radius of Earth. If we want to calculate the distance between two places in kilometers, use the value 6, 378.8, which is the radius of Earth. You'll get the approximate distance.

OR

You can use api like google map, this is the link for more info

this is google map package link that you can use in the flutter app for the same purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM