I'm working on a Geocaching App as a way of learning how this all fits together, and I'm at a point where I've got the app to fetch some JSON from a webserver which looks like this (ignore the coordinate values, these are just for testing, I'm yet to write the full backend!):
When I initialise the screen, I want to set the map coordinates to the lat/lng at the first waypoint (Our House), but I'm really struggling to work out how to iterate over the list.
I've read the documentation and many of the posts on here, but for some reason my brain just can't get it right
This is the relevant block - note that I come from a Python background, so this may just be me holding it wrong!
OK, that worked a treat, thanks, I can get the coordinates from the JSON and pass them to the map, however for some reason they appear to be truncated to 4 decimal places.
I've looked at the format as decimal number block, but even if I set that to 10, the value is truncated to ~4 places.
Obviously this throws the map out by miles, have I missed something somewhere?
Edit: If this should be in a new thread, I'm happy to do that...
Your code is correct in the first post, except for the fact that App Inventor is 1-based rather than 0-based, so for your key path you need to use 1 instead of 0 to get the first element in the list.
A reality check: When working with geocoordinate degrees, the following is an excellent example showing the precision of measurement using various degree decimal places.
decimal places |degrees |distance
0 |1.0 111 km
1 |0.1 11.1 km
2 |0.01 1.11 km
3 |0.001 111 m
4 |0.0001 11.1 m
5 |0.00001 1.11 m
6 |0.000001 |0.111 m
7 |0.0000001 1.11 cm
8 |0.00000001 1.11 mm
10 decimal places is entirely inappropriate. That precision can never be resolved on an MIT Map
5 decimal places is the maximum resolution possible with most gps receivers using the Location control. Newer cell phones have the ability to use multiple constellations to achieve slightly better maximum resolution; the LocationSensor cannot handle those.
I don't know the resolution possible with OpenStreetMaps (Map component) but the resolution is certainly no better than 6 or perhaps 7 places.
the behavior of the directory blocks is interesting
Your Blocks example yields the above information when the lat/long are set to 10 decimal precision as shown in green. The Blocks show what happens if you use the Format Math Blocks to extract the other values. Certainly no problem here.
by miles, hardly. Yes you are missing something somewhere, whether it is how you entered the coordinates on the json file, how you used the Map component or something else is not known because you did not share an example of what happened. You could show a screen capture, block images etc. It is apparent the dictionary blocks display six digits doing a DoIt but all the coded lat/lon information using an unlikely example of 10 digits after doing the DoIt is present. Maybe @ewpatton can explain the DoIT behavior.
When a real number is rendered as a string it is rendered by default with 5 decimal places. Internally the system will use as many places as required to store the original precision though.
We can see that 1/3 is rendered as 0.33333 but the result of adding 1/3 + 1/3 + 1/3 is 1, as expected.
If you try to add the string 0.33333 to itself twice then you only get 0.99999.
If you place the number into a property that coerces it to a text, you will get the same result (because the default is 5 places).
If you use the format as decimal number and give it a high precision, then when the text is converted back to a number it will be approximately the same (within the error limits of an IEEE 754 double floating point number).