Geolocation is supported on all of the devices that are compatible with Rhodes. Native mapping is only supported on the iPhone, BlackBerry, and Android. You can still do mapping on any platform using the web browser and you can use geolocation features without mapping, although they are often used together. The example in this section follows such a typical use case that integrates the results of geolocation into a map.
The example application illustrated in this section allows the user to fill in a web form and check a box to use the current location or optionally fill in a zip code, and then displays all of the locations on a map. The complete application was built to show where conference attendees originated from and can be found at
http://github.com/blazingcloud/rhodes_rubyconf-it is a connected application that saves data to a server via RhoSync, but that isn't required for using geolocation. The example code in this section could be used offline or with other means of connecting to a server.
When testing on the device simulators, you need to be aware of how to simulate your location. On the iPhone simulator, your current location is always 1 Infinite Loop, Cupertino, CA (Apple's headquarters). On the BlackBerry, you can set the location through the menu on the simulator. On the Android, you connect to the emulator using netcat (see Listing 6-12) and send a "geo fix" command. Note that the two numbers following geo fix are longitude then latitude.
Listing 6-12. Using netcat to set the current location in the Android emulator. nc localhost 5554
Android Console: type 'help' for a list of commands OK
For the native mapping to work on the Android, you need to install the "Google APIs by Google Inc., Android API 3"package and then you can use the Google Map capabilities. To do that, run android/android-sdk-r04-mac_86/tools/android (you'll see a window appear), click Settings, check Force https://... sources to be fetched using http://... and press Save&Apply. Then select the Available item in left list, expand https://dl-ssl.google.com/ , check package Google APIs by Google Inc., Android API 3, revision x and press Install selected.
Then you'll need to obtain your own Google API key for Android as described here: http://code.google.com/intl/en/android/add-ons/google-apis/mapkey.html and add it to application's build.yml (see Listing 6-13).
Listing 6-13. Section of build.yml file with Android configuration android: mapping: yes
# http://code.google.com/intl/en/android/add-ons/google-apis/mapkey.html apikey: "XXXYYYcZzZzvAaBbCcdddDDDXXX999"
Was this article helpful?
Discover how a single application could generate $1000's of dollars, instantly. The simple, low cost system for outsourcing app development to freelancers. How to quickly evaluate applications so you can create a high profit one of your very own. The fastest way to leverage the popularity of iPhone and iPad apps to skyrocket your income. Top methods for promoting your application for maximum exposure.