Getting your current position using GeoLocation
Our map may be working, but it is currently hardcoded to appear above London, England, and not all of us live and work in that big city. One of the great things about mapping technology is that we can determine our location from anywhere in the world via GPS satellites, Wi-Fi networks, and cellphone towers. This allows you to put maps into context, and lets you issue data to your user that is targeted to their physical location.
In order to get our current location, we need to use the Ti.Geolocation
namespace, which contains a method called getCurrentPosition
. The next recipe will explain how to use this namespace to adjust the bounds of the MapView
to your current location.
The complete source code for this recipe can be found in the /Chapter 3/Recipe 2
folder.
How to do it...
Add in the following code after you have added your MapView
component to the window:
//apple now requires this parameter so it can inform the user //of why you are accessing...