Determining if a user's location is within the boundaries of a FeatureCollection Polygon


I can barely read any of the Blocks Jay.

Please post a clear image of your Blocks. Is the circled code supposed to post the current user's location in the Marker or what? Have you performed a DoIt debug on the LocationSensor.Latitude/Longitude. What values do they show? How to use DoIt by Ennis Knowing the values indicate whether you are getting GPS information. You might be showing 0,0 if you are not using the LocationChangedEvent or set TimeInterval to short or do not wait until your gps reports a satellite fix (and a LocatonChangedEvent).

Glad to help but your images showing how you use the database are useless. Here is what I do know:

  • want to get the location of the user ---use the LocationSensor

  • find the three counties in the state of the user which have the most COVID-19 cases --you have to determine the state of the user using the coordinates from the LocationSensor then consult the database and search for the state

  • I want to display this information on a map. --- what information? the user's location Marker, the dots ? The code displays circles around those counties with the most COVID-19 cases in the particular state and when the circle is clicked, it displays the number of COVID-19 cases in that county. So, I imagine you want to post three circles and the Marker. -- ok, realize I can't see that or what it is supposed to look like.

  • Additionally, if the user is located in one of the three counties with the most COVID-19 cases in the state -- sorry, you cannot determine that with your present code. Your database probably provides the centroid coordinates of each county. The locationsensor will provide the actual user location. It is highly improbable that the two will ever be identical; it will never happen. To compare them the values for lat/lon must be identical.

  • the app sends a notification to the user. --Ok can't read your blocks so you might be alriight

  • My code works fine when I plug in an actual coordinate for the latitude and longitude --- really? Do you plug in the county centroid coordinates? Try any other coordinates that is within the county and your code will fail

  • but the location sensor doesn't seem to be able to pick up the pair by itself. -- sorry, I do not understand what pair it is supposed to pick up. It will NEVER have the exact coordinates of the centroid. You should be trying to establish, perhaps using a geojson of COUNTIES, whether the user is located in any of those counties. Your states geojson is large and has issues loading; the county geojson for the US is three to four times the states geojson. Will counties even load? I don't know.

  • The set Web1.url block links to a website which is an updated COVID-19 database with number of cases per county for each U.S state. Also, File 2 is a google sheet with longitude and latitude pairs for each county in the U.S. --- both of these are interesting ideas.

Very interesting idea. Part is working. Congratulations. I imagine the part not working includes establishing whether the user is located within one of the high covid plague counties. You cannot do that with the information you have available to you. Sorry. :frowning: You can indicate the person is in the state and let him/her know graphically he/she is near one of the counties by showing the circles and the Marker on the map. You can also determine the distance from each circle to the user and tell that person how far they live from the counties with the highest plague counts. There is a block that calculates distance. You cannot equivocally tell that person a person is located in one of those troublesome counties without a county map outline.

Keep working on your app. Interesting ideas, difficult to implement. Parts do work so feel good and implement what is possible.

-- Steve

Sorry about pictures. I have posted new ones below.

  1. The circled code is just supposed to set the marker to the latitude and longitude of the user.
  2. I have not performed a Dolt debug so I'll try that out right now.
  3. I want to display the three circles and marker on the map (that is what I was referring to when I said 'information on a map'.
  4. I forgot to take a screenshot of a portion of my code which gives a notification to the user if he/she is currently in one of those counties with the most COVID-19 cases. I have pasted that code below (in purple).
  5. I am using the google sheets information (state, county, longitude, latitude) just to place the three circles on the three particular counties (on the map) with the most COVID-19 cases. Nothing else. I am accomplishing the task of finding if the user is in one of the counties using the 'Marker Distance to feature block' (that code is below as well).
  6. My code works when I plug in a longitude and latitude pair for the user's location. My code does not fail even when I try another longitude and latitude pair in a county. I have explained what I am doing with the google sheets in number 5 (I may have not been clear before).
  7. The Location sensor is not able to detect a longitude and latitude pair of my Android device. I will surely try the Dolt debug to see what the problem is. I may need a 'When Location Changed' block.
  8. I do not need a county geojson as the 'Distance to feature' block works for me. Did my state geojson not load for you? I do remember that I have to update the Source of the Feature Collection everytime I run the app and it takes about 20 seconds.

I hope that makes my app a bit more clear. Thank you for all your help!

Please note that after the first two pictures, all the rest of the pictures are one block but are separated so that it is easier to read the code.

I tried the Dolt debugger (very helpful tool) and I am getting 0,0 for both the location sensor latitude and longitude. You suggested that I should use a Location Changed Event; what do you suggest that I put in this event?

One step at a time.

Part of the problem with 0,0 is this

When the Screen2 is initialized, the default coordinates are as you discovered 0,0 because when those Blocks attempt to set the Marker, the GPS has not yet realized a satellite fix to find out where it is located. I do not know what you have on Screen1 but attempting to use the LocationSensor before a fix is achieved causes issues. Simply, the circled code is misplaced and I don't know an easy way to fix your issue.

If you use a single screen (or virtual screens), you could do this

Setting the TimeInterval is important, however it means that you still will not have a Marker on initialization. The initial satellite fix takes about 40 to 60 seconds using most hardware.

A way to get around the issue is to place some of the code into a Clock and allow it to continue checking for valid latitude/longitude until the lat/lon is no longer 0,0 and then, and only then to display your map. The Blocks with orange dots are not necessary but you will have to use them if you display the map on the second screen.

What you might do, to experiment, is to use a start Button to display the marker (an even your map) on your second screen to get the user latitude and longitude like this after waiting for 30 or 40 seconds

Got to run! Sorry, there are more eloquent ways but not time.

Thank you Steve for all this help! You informed me about the problem in my code! I realized that the Location sensor needs some time to read the longitude/latitude of the user as well as the current address of the user. My code previously was not waiting for the location sensor to load all this information and thus, I was getting nothing for the address and the latitude/longitude. What I've done with my code is that I am not allowing my code to run if the location sensor has not yet detected the latitude/longitude. This code is finally working for me and I realized that I don't need the geojson file and the polygons anymore because I can detect the address of the user (which was my previous idea). However, the working code that I have pasted below includes the latitude/longitude feature and the geojson file. I may change my code to incorporate the location sensor address instead of using the latitude/longitude of the user.

Again, thank you for all the help. I truly appreciate it.

Looks reasonable Jay. Yes, you got it. Good luck with your Project.

-- Steve

A post was split to a new topic: Documentation request for the LocationSensor

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.