Walkplanner -- an android mapping exercise

For this project we are going to do a little bit with maps and location finding.

While you are connected to wifi, you can easily browse the maps of the world on your phone. This is dandy, if you want to know about the suburbs of Mumbai while reading a newspaper article at home. But if you are walking from the university to downtown Birzeit, you are probably not connected to wifi, and if you want to figure out how far you have left to go, you might be out of luck.

There are two different problems you'll face:

There are apps to address these problems, and we are going to write another.

Keeping a database of maps in the phone

If you were planning a walk in an unfamiliar place, you might go over the route, and download a batch of maps which would show your route in some detail, and extend beyond it in all directions. I like the OpenStreetMap maps, which seem to have better detail in Palestine than Google maps, and which are also open source. If you use the browser, you can save the maptiles it is looking at by doing a save page, but OpenStreetMap doesn't want you to write them into your apps, so anything more automated requires you to use a more compliant server: mqcdn.com serves the same data without complaint. Check out http://developer.mapquest.com/web/products/open/map

For this project, you are not required to download maps at all, although I'll be talking about it during the month. Instead, I chose a well-known location near the center of the universe, and provided a few maptiles around it. Each tile has a name based on a row-column position. So 0_0.png is row 0, column 0, and 1_3.png is row 1, column 3.

I put the tiles in a webpage here.

You can download the 24 files as a zipfile here. These few maps will fit handily into the assets directory, or even the drawables directory of your app. Assets is better, because drawables have funny integer names like R.drawable.0_0 which you can't easily do arithmetic on. (I have in the past, and so far those apps haven't broken, but I expect it to happen any day.)

I renamed these tiles to reflect their true importance. Presumably we could find any other location on earth with the same coordinate system. There is a discussion of the Open Street Map naming scheme at http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames These bitmaps are all at zoom level 16. The scale changes by a factor of two between levels, with 19 being the highest level of zoom I've noticed. At a zoom level of 0, the whole earth fits on a single tile, and the flaws of the Mercator projection are obvious as the continent of Antarctica becomes huge. At a zoom level of 16, 4 billion maptiles would be necessary to cover the whole Earth. You could probably fit this many tiles on a 16 GB SD card, maybe with a little bit to spare. A zoom level of 17 would require four times as much space. It might still fit, because many of the tiles in the ocean are pretty boring, and compress to quite small PNG files.

Finding your location with nearby wifi networks

If you knew where the MAC addresses of every router in the area you travel, you could look for nearby wifi networks and use that information to tell where you were. Since the signal from each router doesn't go very far, that's pretty precise information, but you could probably do even better by using signal strength and looking at the location of several nearby routers.

Here's some code to sample the nearby router addresses.

wm = (WifiManager)getSystemService(WIFI_SERVICE); ArrayList<ScanResult> asr = new ArrayList<ScanResult>(wm.getScanResults()); for (ScanResult sr : asr) { addStuff(" wifi:" + sr.BSSID); }

What I want you to do:

You've used on-line maps; what I want you to do is
  1. write an app which uses the 24 maps I've provided to display a square map on the screen of the phone.
  2. You'll be able to move the map east, west, south, or north by touch motions.
  3. Zoom-in and Zoom-out buttons will let you magnify the image or make it smaller. (Open Street Map zooms only in factors of two, by using maptiles which are already zoomed. But we have a simple API for displaying bitmaps in various sizes, and I've only provided one zoom level of the map.
  4. The center of the map will have a red dot.
  5. Text at the bottom of the map will display "Data provided by OpenStreetMap.org"
  6. A TextView will show the (floating) row, column coordinates of the center of the screen, which range from 0,0 to 3.99,5.99. (A hundredth of a column is about 5 meters. That's pretty close.)
  7. An EditText will show the MAC addresses the phone can currently see. This is an EditText, so that you can record addresses in the emulator, which doesn't emulate wifi. If you use this feature, you should probably disable actually collecting addresses, since the emulator will never find any...
  8. A button will let you save the the "location" of those Mac addresses as the coordinates of the red dot.
  9. A green dot will appear on the screen showing the saved coordinates for each of the saved MAC addresses which you can currently see. So presumably your current location is near any green dots on the map. If you scroll the map so that the red dot is surrounded by green dots, you should be at the location of the red dot ...

    Some MAC addresses will be visible from different points, so depending on whether you saved them more than once , they may appear more than once. Obviously when you save the currently visible addresses, the center dot could turn green.

  10. When you scroll beyond the area of the map, that is, beyond the 24 map tiles, the screen will show blank space for that area, but will continue to handle the other features, including the red and green dots and the row-column coordinates of the red dot.

What I want you to turn in:

  1. Journal
  2. Screenshots
  3. All your Code. Many people have been sending me archives of the project, which is easier for you than attaching many source files to an email, and has the nice side-effect that I can download and run the .apk file.
Submit this project in Ritaj.