Sie sind auf Seite 1von 3

12/13/2014

Walkplanner -- an android mapping exercise

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:
Google maps can't download the map if it isn't connected to a network. If you happened to be
looking at the map before you started out, it may still show, but you can't zoom or slide it.
Google maps shows your position on the map, and which way you are facing, if it can figure it
out. There are three different ways to figure out your location:
1. GPS, which almost all Android phones have. But GPS uses a lot of battery, and most
people keep it turned off. You could turn it on for a couple of minutes to check your
position, but it would have to be at least a couple of minutes, because it takes almost a
minute to calibrate the clock on the phone with the satellite clocks, and you should let the
phone take several measurements before you believe it.
2. Nearby cell phone towers. It turns out that every tower has a number. So if you check the
number of the nearest tower, and you happen to know where every tower is, you know
your approximate location. (On some phones, you can ask the number of all the towers in
reach, which would give you more data to work with, but on mine that call returns null.)
The catch is that there are a lot of cellphone towers in the world, and new ones are added
all the time. So instead of keeping that data in the phone, google has elected to keep it in
the cloud. Once you lose your wifi connection, you can't reference that database.
3. Nearby wifi networks. Of course most of them are secured, and you can't use them, unless
you know the password, but most of them show up on the phone, and certainly on the
airways. And every one of them has a 48-bit MAC address, and those MAC addresses are
all unique (to the hardware, not to the location) so if you only had a world-wide database
of all the MAC addresses in use, you could tell where you were by looking at nearby wifi
routers. (At least when you were in town.)
Again, Google software uses wifi to look up the MAC addresses on a database in the
cloud. So you're okay at home, except that when you're home, you know where you are.
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.
http://computersystemsartists.net/fall14/android/projects/walk-planner/walk-planner.htm

1/3

12/13/2014

Walkplanner -- an android mapping exercise

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.
http://computersystemsartists.net/fall14/android/projects/walk-planner/walk-planner.htm

2/3

12/13/2014

Walkplanner -- an android mapping exercise

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.

http://computersystemsartists.net/fall14/android/projects/walk-planner/walk-planner.htm

3/3

Das könnte Ihnen auch gefallen