# How to determine the mosques closest to you through kodular

How to determine the mosques closest to you through kodular

• Create a list of mosques with their coordinates in a JSON file, and then upload the file to the assets.

• With a File component, read the JSON file.

• With the LocationSensor component, read the location of the user (latitude and longitude).

• Using the Haversine formula, find the mosque with eh closest distance.

1 Like

Use APIs
You will find Tons of Geocoding APIs
Try This one :

Thatâ€™s Way too complex & Huge

Haversine formula?

Can you make a simple video of the establishment of the nearest mosques

Just once Try Yourself. It will Increase Your Logic to build Code
just Saying

btw I am making a guide on this soon anyways

No. This works offline, and helps you train your math and thinking skills. Actually, itâ€™s not even â€śhugeâ€ť. Plus, my method is not subject to any quota usage, unlike your API. Only 108 blocks are used, so itâ€™s pretty acceptable.

In this example, I am testing for the closest Hong Kong MTR (Underground) station.

I took part of the code for the Haversine forumla here (credit @juananton1991): Map distance Haversine. Marker. Drag. LineString - Tutorials and Guides - MIT App Inventor Community

JSON:

``````[["Kennedy Town", 22.281250727387963, 114.12886429458312],
["Sheung Wan", 22.286596376377837, 114.15183691762358],
["Central", 22.281953215872946, 114.15818049600362],
["Causeway Bay", 22.28040802199333, 114.18511814336304],
["Fortress Hill", 22.288012978467332, 114.1935168988797],
["North Point", 22.29139899385995, 114.2004158766255],
["Tai Koo", 22.284682391482125, 114.2162235347446],
["Sai Wan Ho", 22.282101131965682, 114.22165273079993],
["Chai Wan", 22.264626227177658, 114.23690142055202]]
``````

Blocks:

Output:

It gives me a result of 474.6m. Currently I am 486.1m away, so it is pretty close.

AIA: MTRStations.aia (6.2 KB)