Over a million developers have joined DZone.

Using Geolocation with Flex in the Browser

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

I went to http://www.html5rocks.com, and some of the samples didn’t work. The one that did, however, was Geolocation. I thought it was neat because you didn’t need to utilize an iPhone/Android phone to get Geolocation data, and thus know where you are. I’ve read on Twitter that it’s not very accurate. Not sure how it works, but it’s been accurate for me. The browser support, however, has been atrocious. So far, the sample below only works in Chrome and Opera. Safari and Firefox don’t seem to work for me. Safari does pop up the permission dialogue, but just sits there; no error, no update. Regardless, I wanted to see if I could integrate that location data into Flash.

If you’re running in AIR2 or Flash Lite 4, there is already a native Geolocation API You can utilize straight from ActionScript 3. If you’re in the browser on the desktop, however, it’s not available unless you tap into the browser API’s which I’ve done.

You expose the browser API’s you need via JavaScript, and just have Flex talk to JavaScript, and JavaScript talk to it. This example puts a marker on the map once it gets your location. While not needed, if you want to utilize in your own applications, you’ll need a Google Maps key.

Source Code

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Published at DZone with permission of Jesse Warden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}