How do I set up my map to pull data (from a zipcode or an address)?

Here's my issue - I created a variable on the first screen and initialized it to an empty list. I then had a text box and a button, the user can enter data (Data is a ZipCode) into the text box and then hit the button to add it to my list. On my second screen I have a map. I want to pull that zip code from my list and set the map to it's location. Is there anyway to do this? Is latitude and longitude needed? If so, how do I accomplish that.

If you read this and need any further details let me know and I can provide them.

You need the Location Sensor component and blocks something like this:

which will return your lat and lon, which you can then apply to your map.

(Working OK for UK postal codes, test on a real device)

I'm confused how to do this. The data being entered is just a zip code. Do I need to change that so the user would enter an address instead? Also how do I get this across multiple screens. I attached files below to show you what I'm working with. Both of these are on screen 1. I have a map on screen 2.

Screenshot 2025-05-26 11.42.34 AM

In the code, textbox3 refers to the green box on screen, and zip code is the button with the instructional text. I set it up so that once the user enters their zip code they can't add another one because I felt that was easiest to prevent the user from confusing the map. The goal is that the user enters their data, it goes to the list, or the ZipCode Variable, and then the map on the next screen pulls that value and uses it for its location.

Also I'm new to this community, does a "power user" like you get paid to do this as a job, or do you voluntarily help others? Either way I appreciate your help.

Sorry, I wasn't clear, the postal code (zip code), is entered in the textbox I showed in my blocks. If this doesn't return a reasonably accurate lat/lon, then you may need to find a different method.

You can choose whether you want to return the lat/lon in the first screen or the map screen.

Power Users are volunteers

Thank you, I'll give it a shot.

Oh, I think I've realized my issue. I'm trying to create an app that allows the user to input a zip code. My issue isn't finding out what that latitude and longitude for that given zip code is. It's figuring out how I can get the code to pull the user's zip code from a different screen and then apply it to the map to present the user with a map of their location. If needed I can move the zip code enter box to the page with the map to prevent having to store the data over multiple screens because that seems like it might be difficult.

As I said, it is up to you where you get the lat/lon (on which screen), remember you need to give time for the locationSensor to get working.

I would also suggest you use the CentreToString when setting the coordinates, PanTo can give some strange results.

You might also consider if there is any real need to do it on separate screens at all ? Consider using virtual screens ?

I didn't know what a virtual screen was. How does that work? Is ready the description with a button and arrangements. Is the point of that to add invisible data to a screen?

I'm very new to this if you couldn't tell. Trying to get a better hang of it to complete an assignment I have for a class.

See tip 1 here

Taifun

You are using the wrong tool if you use a zip code to determine where someone is located on a map tool. Zip codes outline areas where a postal code in effect. In most places the Zip code includes all addresses within this area. A location based ONLY on a zip code database can not specifically tell show you were someone is located; it only will provide the latitude and longitude of the centroid of a zip code. The centroid is not necessarily someone's precise location (but might be somewhere near where they are). Are you telling us you have a List of coordinates corresponding to Zip codes in a database on the other Screen? For example, this link is a database showing the latitude/longitude for centroids of all the Zip codes in the USA.. To determine where the Zip code is, you would search the List for the Zip code you want. When you determine the coordinates of the centroid you can use a Map component or Google Maps to display a map near the zip code centroid. You can find a map of the USA Zip code actual boundary obtainable from the US Census Bureau. if you want a map showing the boundaries of the zip code in several formats.

You definitely need a data table for the zip codes, or have a really good location service active on the phone.

This is a failed attempt without a database:
image


location_sensor.aia (2.3 KB)

It's a failure because the geocoding service does not come close enough to the zip code boundaries if you just enter a zip code.

It does get the city right, if it's the same city where you live.

It also can't show the zip code boundaries, because the map doesn't know them nor does the location service tell you them.

No, I didn't create a list. I attempted to just have the user enters their location and then the map could pull that from a dynamic list to show them there location.

Should I create a database and then do something similar to your code ABG? I could use the list SteveJG provided me with that gives the centroids of all the zip codes in the US. However, if I can't copy it in and have to manually type it out that would be a struggle.

Should I just have the user enter their zip code or whatever location I decide to use on the same screen as the map?

This looks a little confusing to me. I'm unfamiliar with a lot of the more complex components. Still figuring out the program.

It was bang on centre of my postcode in the UK. Depends on whether close enough is good enough.

It looks like you need to do a little reading.

Is this your first project?

Which tutorials have you done?

Since you will be using the Map component, you should be familiar with the attributes and blocks of the Map component.

See
https://ai2.appinventor.mit.edu/reference/components/maps.html#Map
for all the display features for sizing and especially the Pan To block.

You will need to upload a zip code table into the Media folder in the Designer, and load a lookup table from it in Screen1.Initialize.

Then you will need to learn to do table lookups.

Here's your Comma Separated Values (CSV) table, from @SteveJG's link:

US20Codes20201320Data.txt (906.3 KB)

Here are some sample projects that load tables from the Media folder and do lookups: