-
-
Notifications
You must be signed in to change notification settings - Fork 24
Description
On a fine evening...
In my village at Temerloh, Pahang, while waiting for the Iftar time, I opened up this MPT app to set the new location to my current location here at the village:
So, the detected location is correct (Felda Sg Kemahal), so I select OK (PHG03). But then, I remembered my mom told me a long time ago that at kampung, we follow the time at Bentong (PHG04). So, to confirm, I opened up e-solat JAKIM portal. The portal has the ability to auto detect the user prayer time zones. 👍
The portal detected my location in PHG04, which as my mom said. Later, the azan berkumandang at the same time, which double triple confirmed the information.
I wonder
Was the location detection 'algorithm' being not accurate to determine the user location? If so, then I in a big trouble. 😓
My current detection method to determine the user location is by taking their coordinates and find the nearest places in the negeri. The nearest places will be the user's prayer time zones. I remembered that I've tested this method in the beginning in the development and the result was great.
The implementation
app_waktu_solat_malaysia/lib/location_utils/location_coordinate.dart
Lines 1566 to 1599 in 2c71e50
| /// Return nearest JAKIM code from the given coordinate and negeri. | |
| /// Pass administrative area as negeri. | |
| static String getJakimCodeNearby( | |
| double latitude, double longitude, String? negeri) { | |
| // when user is on perairan (kawasan air), negeri xdetect. | |
| if (negeri == null || negeri.isEmpty) { | |
| throw "Area not detected. Are you on a boat?"; | |
| } | |
| List<int> tempIndex = []; | |
| double nearestDistance = 50000; //init distance to be 50 km | |
| late int nearestIndex; | |
| for (var i = 0; i < _locationCoordinate.length; i++) { | |
| if (_locationCoordinate[i].negeri == negeri) { | |
| // collect index of the same negeri | |
| tempIndex.add(i); | |
| } | |
| } | |
| for (var index in tempIndex) { | |
| // calculate distance each of indexes location with user location | |
| double distance = Geolocator.distanceBetween(latitude, longitude, | |
| _locationCoordinate[index].lat!, _locationCoordinate[index].lng!); | |
| // distance returned in meter | |
| if (distance.compareTo(nearestDistance) == -1) { | |
| // check the shortest distance | |
| nearestDistance = distance; | |
| nearestIndex = index; | |
| } | |
| } | |
| // return the nearby jakim code | |
| return _locationCoordinate[nearestIndex].zone; | |
| } |
Edit: Above implementation will be moved to the server side. Check out https://waktusolat.iqfareez.com/api#tag/zones/operation/getZonesbyGps
Same 'algorithm', just processing will be handled by the server, so the problem isn't solved yet.
Resolution
- Let's conduct an experiment to see how different apps out there perform (cont'd below)

