Monday, November 15, 2010

Sample of FVM code

For those of you interested in how the code looks in the FVM app, here is a sample, as it appears in the IDE:

This snippet is called every time the GPS gives the app a new set of coordinates ...

public void onLocationChanged(Location currentLoc)
{
currentLoc.getLatitude();
currentLoc.getLongitude();

// This grabs the location data from an external file.
locations = res.getTextArray(R.array.locations);

// This loop goes through each location in that file...
for (int i = 0; i < locations.length; i++) {
String[] loc_data;
loc_data = locations[i].toString().split("%%");

Location landmark = new Location(currentLoc);

// ... and then loads up the lat/lon
landmark.setLatitude(Double.valueOf(loc_data[1]).doubleValue());
landmark.setLongitude(Double.valueOf(loc_data[2]).doubleValue());

// ... and checks to see if that is within 5 meters of where we are standing.
if (currentLoc.distanceTo(landmark) < 5) {
// ... code to handle launching videos, slideshows, etc. goes in here
// but has been snipped out for brevity.
}
}

}

No comments:

Post a Comment