INeedIt - Simple Flex Mobile example

This post is more than 2 years old.

I've been wanting to get back into Flex Mobile ever since the release of Flash Builder 4.5. Now that it's out - and now that I'm past cfObjective, I thought I'd whip up a quick demo. I still need to - you know - actually read up the docs a bit. What follows is... rough... but when it works it's kinda cool and I think it's a cool idea. Flex users please feel free to rip me a new one and help me improve the code.

A few days ago Google released an official public API for Places. The API allows you to get information about certain types of businesses based on location. So you could say, find me all the banks next to long/lat and within so many meters. Once you got the results, you could then get details. I noticed that quite a few types were supported by the API. I thought it might be cool to create a simple application that...

  1. Finds out where you are using Geolocation

  1. Provides a list of everything Places supports

  1. Let's you pick one and then load the results

  1. Let you pick a place to get details and call them.

Simple enough, right? Here's what I came up with. Note that I'm using screen shots from the emulator which does not support GPS. That's kind of silly I think. I'd love to see it updated to simply mock GPS info.

Once you select a category, like bar, you get a list of results:

And once you click a record, I can show the address, phone number, and a map.

So - here's some issues I'd love some help with:

  • The list view on my phone is too small. In the simulator it looks perfect. How can I make my list items fatter?
  • GPS is ... weird. The Geolocation API is an event handler. Every time the GPS updates it can fire a function. I only need one GPS reading though. But get this. It always reads Lafayette even though I'm in Minneapolis. If I let it run 2 or more times it correctly updates. But when I run the app again it goes right back to Lafayette. It's like it considers Lafayette as home and doesn't refresh it.
  • The Google Map, as you can see above, is a bit ugly. I'm not sure why. It should be higher quality. I assume I'm using the Image component poorly.

And with that, some random other notes:

  • The phone number is clickable. Try it. How could I style that to make it more obvious? Perhaps make it a button with the label being the number?
  • I'm supposed to add a credit logo for Google. I'll add that before I send this to the market. There's also random items for each place you are supposed to add for attributions. I'll need to add that too to be 'legit' with the API.

Ok - so I've attached one zip to this blog entry. The zip has 3 things in it. First is the FXP. If you have Flash Builder, you can import it. I also included a general zip of the project. That's for those of you without Flash Builder, or those who just want to use a text editor to look at the code. Finally, I included the APK you could - in theory - use to install on your phone. My app isn't signed so you will need to allow for that.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Aaron DeRenard posted on 5/15/2011 at 8:09 AM

Moved the apk over to my Incredible, used astro to find it, opened it with App Manager, hit Install and click Open when it was done installing... Menu appears, but nothing seems to be found.

Back out of app, turn on standalone GPS, launch app... Works!

Unfortunately the Places API looks like it doesn't find much of anything where I live (though it should) but some items are coming up and that's awesome! For instance, I would expect Gas Station to show at least 4 entries that are very close to me, but it doesn't show any. But it will show a cemetery that is quite further from me. One store that is next to another, but the other doesn't show (a local store shows, but CVS does not... strange [and I can't say what kind of store CVS is, because my comment gets flagged as spam]).

So what I am trying to say for other readers that try the app out, don't just assume it isn't working after trying 4 or 5 menu items. Try a bunch because it's probably working, just the api isn't returning much. At least that's how it seems to me.

Comment 2 by Ivan Alvarez posted on 5/15/2011 at 9:55 AM

I would recommend you to use the Stagewebview to load maps as Chris did it http://chrisgriffith.wordpr.... I have compiled to iphone 4, ipad and android and works smooth!!

Comment 3 by Mihai Baboi posted on 5/15/2011 at 11:52 AM

That's so cool. I've been looking forward to this post ever since you posted your intention on Twitter. Did it take you an hour, like you said? :D

Comment 4 by Raymond Camden posted on 5/15/2011 at 2:41 PM

@Aaron: I thought I had correctly accounted for both GPS not being available and being off - but I may have missed the 'just being off' part. I've got 3 hours in a layover today so can fix it then. ;)

And yeah - the Places API doesn't have _everything_ for sure.

@Ivan: Thank you - I will try that.

@Mihai: I'd say it took me 3 hours. I spent an hour after the conference and 2 hours after dinner. Forgot that I had never gotten my phone just right on the laptop (driver wise) so that was a hiccup.

Comment 5 by Aaron DeRenard posted on 5/15/2011 at 6:06 PM

@Ray: If I turn off Standalone GPS and Google Location Services, the app just sits on a "Getting your location..." state. If I just turn on Google Location Services, the same cemetery etc is found. So apparently last night was a hiccup in Google Location Services.

So in short, it works fine with Google Location Services and/or Standalone GPS. And the "just being off" part may have been missed as you said.

3 hours? Heh... Good job! I'm impressed.

Comment 6 by Raymond Camden posted on 5/16/2011 at 4:12 PM

I got a chance to test my app back in Lafayette yesterday. While _in_ the airport, Google Places didn't know an airport existed. But it did find nearby restaurants when I picked food. Very cool to see this working.

Also - I forgot to give credit to the AIR Launchpad (http://labs.adobe.com/downl.... It helped me write the GPS stuff and helped me with the splash screen syntax.

Comment 7 by Brian Rinaldi posted on 5/16/2011 at 6:54 PM

I've seen that geolocation issue on my Nexus One (not sure if it's a device issue or not) but I can assure you it's not anything related to AIR as I have seen it on a number of native apps as well.

You can customize the list item appearance using item renderers. For performance purposes it's generally recommended you use ActionScript item renderers rather than MXML. Nahuel Foronda has a great multipart tutorial on it - here's part 1 http://www.asfusion.com/blo...

Comment 8 by Raymond Camden posted on 5/16/2011 at 6:56 PM

Interesting - are you saying I need to do an item renderer just to make the items 'fatter'? Can't I do it via CSS or some such? I know writing item renderers isn't a big deal but it seems like overkill for this, doesn't it?

Comment 9 by Brian Rinaldi posted on 5/16/2011 at 7:04 PM

Appears so. Halo had a rowheight attribute on the List but Spark does not appear to have that. It might be possible with a skin rather than an itemrenderer but I'm not 100% certain (scanned the source with a coworker and saw minheight and maxheight attributes, so that might solve your use case...didn't see a fixed height setting though)

Comment 10 by Raymond Camden posted on 5/16/2011 at 7:08 PM

I'll give that a shot then. Could be a good blog post. What's odd though is that in the simulator it seemed perfect. I know the simulator is much bigger, but in "relation" to the chrome it was bigger. Does that make sense?

Comment 11 by Raymond Camden posted on 5/17/2011 at 8:20 PM

Posted my size/proportion question to Stack Overflow. First time I actually posted a question:

http://stackoverflow.com/qu...

Comment 12 by BNNY posted on 8/9/2011 at 2:06 AM

Can you provide us with the project file?

Comment 13 by Raymond Camden posted on 8/9/2011 at 2:09 AM

The most up to date code may be found here: https://github.com/cfjedima...