Air pollution measurement app

hi! im trying to make an app for pollution measurement using the openweather API (pollution api) and i'm trying to use the gps sensor of my phone in order to place a marker where i am in a map and display the amount of co2,no2,O3 etc...but i'm struggling to do so
can someone help me ?
i'd like to have the same result as Elham_Ali

image

here is a screenshot of the code and the app look atm:


Welcome.

Read the entire discussion at Air pollution measure (Air Quality api's) and you should be able to create this


by reading the contents of your responseContent json file and appropriately parsing it.

1 Like

well,i still don't really know how to make this app,can you share the code you did for it?

OK. There are probably better ways but this code example works with the openweather API. Use a dictionary or an extension to parse the air quality json. This example uses a dictionary, a LocationSensor etc.

Did you get the code to work?

1 Like

hey! thank you for sharing it! im gonna try it in about & hour!
:+1:

yeah,the code looks like its working ,but i dont know how you placed all the labels
can you show me where you placed all of them please?
oh yeah and i got a "select list item:list index too large,attempt to get item number 1 of a list of lengh 0: []"

There is not any magic arrangement; you can place the controls as you like. Here is the Designer

Perhaps you need to uncheck the Clock TimerAlwaysFires and TImerEnabled on the Designer Properties screen. If your problem persists, post an image of your Blocks; you may have not copied everything correctly. It could be something else like not having a satellite fix yet when you press the Get Air Quality Button1.

1 Like

oh okayyyy I thought you had placed labels from 1 to 18 XD

so, the error has been fixed
but the button "get air quality" do nothing when pressed

Press it again perhaps. It will do nothing until the gps gets a satellite fix. Your cell phone has to know where it is located. The quality is a number and a quality. Like 1 Good .

1 Like

nope,still nothing ,here's the code ,maybe something is wrong in it

image

:cry: Several guesses:

  • You did not input your openweather api password correctly. Check for a trailing space.
  • Your device system is not set to use gps
    LocationSettings
  • A required property is not set on the Designer. Which one, I don't know.
  • You are not connected to WIFI or Data
  • You are not waiting long enough to achieve a satellite fix before pressing the button. Wait at least 30 to seconds the first time you press it.
  • Something else. Try this aia, but 1st modify the code in the Web1 url so your openmap api password is used. I have disabled mine.
    AirQuality.aia (6.8 KB) The app does not work without the required free password from openmap.
1 Like

Did you ever ask for LocationPermission ? I cant see it in your blocks.

1 Like

thank you for the suggestion
i added this
image
but now i got an error :"access.mock location has been denied,check parameters something..."

1 Like

what version of Android are you using. At least for Android 8.1 and lower, the Permission Block ask is NOT needed. In fact, coding it could be causing your latest error by including it. Also there would be no reason to request Permission MockLocation in any case.

The aia also works on an Android 11 cell phone. Unless you are Android 12, there almost certainly isn't any reason to modify the aia code.

Did you try the attached aia I provided and set up your openmap api password?

1 Like

how are you testing? inside a building? go outside with your device to get a good gps signal...
Taifun

2 Likes

Just ask for Fine Location and if required, Coarse Location. I dont think Mock Location and Location Extra Commands would be needed.

1 Like

so,i tried going outside with my phone (android 7) but still nothing,parameters are ok with location permissions
i tested multiple locations but still nothing
i'm now going to try with the .aia @SteveJG gave me,but i dont know how to setup my "open api password" are you speaking of the api key?
ty

oh yeah and i removed every .askforpermission except the fine.location one

yes. Download the aia; replace the api key with yours, then run the app. Be aware you may have to press the Button several times (until your gps achieves a satellite fix) and the wait between presses may need to be 30 to 60 seconds. Good luck.

Just test the aia. Do not ask for permission. It should not be required.

1 Like

yay! it works! i think my code wasnt working because of "call map1 .PanTo" missing for some reason lol
thank you for helping me out!
i'll set your message that contain the .aia as solution, is it okay for you?

3 Likes