Sunday, October 17, 2010

Android App Inventor - Location

I recently got a new HTC Desire phone. One of the main reasons for purchasing an Android phone was the ability to write and deploy my own applications to it. Just prior to getting the phone I had seen a post from Google regarding the new App Inventor for Android tool. The tool is in beta at this time so I signed up hoping that I would get an invite and I would be try out this new tool. Last week I got the invite and started playing with App Inventor.

As I am interested in GPS and location aware applications I decided to develop a small application that would show the current location, current address and the option to launch the Google Maps application on the phone.

 The Android App Inventor is a web application that has a visual GUI builder to create the GUI and uses 'blocks' in place of code to provide the logic in the application.

The screenshot below shows the GUI builder with the 4 controls used to display the current latitude and longitude and the street address if known from the Google geocoding service. It also has a button to initiate the display of a Google map centered on the current co-ordinates.

To obtain the GPS co-ordinates you will need to add a LocationSensor to the non-visible components. This sensor allows you to access the built-in GPS on Android devices. It includes methods to enable/disable the internal location sensor, read the sensors and get the current address.

The next screenshot shows the logic required to display the latitude, longitude and address on the screen whenever the phone is moved.

It also shows the logic for the ActivityStarter to create and display a Google Map. Information on how to setup the properties for the Google Maps ActivityStarter is in the MapTour tutorial.



Once the properties are configured you will need to generate the URI to pass to the Map Activity. I have shown this above as it took a couple of attempts to get this right. As it is not currently possible to simulate the location sensor in App Inventor the app will need to be compiled and deployed to either the Android SDK emulator or a real phone.I did this a number of times prior to getting it to work.

I hope this information helps if you are trying to use LocationSensor and Google Maps activities on App Inventor.

I have added a link to the source code here.

My other App Inventor tutorials are here:
App Inventor - Lists
App Inventor - SMS Services

8 comments:

  1. Thanks for the great post! I am trying to use the current location to bring up directions to a destination. Any Ideas?

    ReplyDelete
  2. Thank you for the examples. They really helped me out.

    ReplyDelete
  3. Hi Dave, Thank you for such useful post. It helps to find and pinpoint a desired location on the map. But how can I get directions from my current location to the desired selected location in the same app.

    ReplyDelete
  4. hello,I'm writing from Spain,sorry I don't speak English very well,I have a problem,I try show my mobile location (my personal google latitude) into the application that I been building but i don't know how to make it,I think that your application "location" is very similar than mine but,
    I want to show the location of my mobile phone not the location of the phone that you have installed the application.
    The application is not for my phone,will be installed on the phone of my customers.
    you show me how I can do building of the block's in app inventor?Thank you

    ReplyDelete
  5. The good information got from this post which is related with Android app Inventor.This is very useful app for me or other android user so thanks for giving this information.

    ReplyDelete
  6. I really like and appreciate your post. Seriously appreciate it! Really Cool.

    ReplyDelete
  7. I want to make a app in app inventor which can tell the distance of using the two location coordinates and can also tell the speed of the vehicle which is coming towards us by using its coordinates 4 -5 times at equal intervals

    ReplyDelete