<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>SnippetRepoBrowser</title>
    <link>http://snippet.gnstudio.com/snippetrepobrowser/index</link>    
    <description>RSS Feed of SnippetRepoBrowser (Global RSS)</description>    
    <language>en-us</language>
    <pubDate>Thu, 09 Feb 2012 21:14:38 +0100</pubDate>
    <docs>SnippetRepoBrowser/index</docs>
    <generator>SnippetRepoBrowser Feed Generator</generator>
    <item>
      <title><![CDATA[Build a STORE LOCATOR using FLEX GOOGLE MAP]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/4</link>
      <description><![CDATA[I was playing with the Flex Google Map API and I think one of the coolest stuff is the Direction feature.<br /><br />In few words, you can do a query like this: &#39;from Milano to Torino&#39; and you&#39;ll get:<br />1) Distance<br />2) Trip duration<br />3) The complete travel displayed on Google Map<br />4) Many other usefull info (check GoogleMap website to get the API reference and other samples)<br /><br />In this script I simulate a Store Locator, where user digits its city in a TextInput and at the same time he can selects a store from a List.<br />Each time user will change selection we&#39;ll show the trip information (Distance + trip duration) displaying visual directions on the map too. <br /><br /><img alt="" src="http://www.fabiobiondi.com/blog/wp-content/uploads/2009/08/gmapsample.jpg" border="0" /><br /><span style="font-weight:bold"><span style="font-size: 10pt"><a href="http://www.fabiobiondi.com/blog/wp-content/uploads/2009/08/storelocator.swf" target="_blank"></a></span></span><br /><span style="font-weight:bold"><span style="font-size: 10pt"><a href="http://www.fabiobiondi.com/blog/wp-content/uploads/2009/08/storelocator.swf" target="_blank">See a live demo</a></span></span><br /><br />But you can do more... check the <a href="http://code.google.com/intl/it/apis/maps/documentation/flash/" target="_blank">Google Map Api web site</a> for more info<br />and remember to <a href="http://code.google.com/intl/it/apis/maps/signup.html" target="_blank">sign up for a key</a> or you won&#39;t be able to use GMAP on your web site<br /><span style="font-weight:bold"></span><br /><span style="font-weight:bold">FLEX CODE:</span><br />Create a new Flex Project and copy all the following code inside your main mxml file.<br />Remember to download the <a href="http://code.google.com/intl/it/apis/maps/documentation/flash/" target="_blank">GMap Flex SWC</a> component and to copy it on your <span style="font-style:italic">libs </span>folder<br />]]><![CDATA[<div class="divcode"><pre lang="actionscript">&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;mx:Application xmlns:mx=&quot;<a href="http://www.adobe.com/2006/mxml&quot;" target="_blank"><a href="http://www.adobe.com/2006/mxml&quot;" target="_blank">http://www.adobe.com/2006/mxml&quot;</a></a> xmlns:maps=&quot;com.google.maps.*&quot; <br />	layout=&quot;absolute&quot; <br />	width=&quot;100%&quot; height=&quot;100%&quot; &gt;<br />  <br /><br />   &lt;mx:Script&gt;<br />       &lt;![CDATA[<br />       	import mx.events.ListEvent;<br />        import com.google.maps.interfaces.IPolyline;<br />        import com.google.maps.Map;<br />        import com.google.maps.MapEvent;<br />        import com.google.maps.LatLng;<br />        import com.google.maps.LatLngBounds;<br />        import com.google.maps.overlays.Marker;<br />        import com.google.maps.overlays.MarkerOptions;<br />        import com.google.maps.controls.ControlPosition;<br />        import com.google.maps.controls.MapTypeControl;<br />        import com.google.maps.services.*;<br />        import com.google.maps.MapAction;<br />        <br />        import mx.controls.Alert;<br />        import mx.collections.ArrayCollection;<br />            <br />        private var dir:Directions;<br />        <br />        <br />        /**<br />        * This method is called when the default Map is loaded <br />        * <br />        */<br />        private function onMapReady(event:Event):void {<br />            setupDirections();<br />            controlPanel.enabled = true;<br />        }<br />        <br />        /**<br />        * Define Direction class and its listeners <br />        * <br />        */<br />        private function setupDirections():void {    <br />        	<br />            dir = new Directions();<br />            dir.addEventListener(DirectionsEvent.DIRECTIONS_SUCCESS, onDirLoad);<br />            dir.addEventListener(DirectionsEvent.DIRECTIONS_FAILURE, onDirFail);<br />        }<br />        <br />        <br />        /**<br />        * Start a GMap Call to get distance between the selected store city and the user city <br />        * <br />        */<br />        private function processForm(event:ListEvent=null):void {<br />        	<br />        	// Set Directions Options (see GMAP API doc for properties details)<br />            var opts:DirectionsOptions = new DirectionsOptions({locale: &quot;English&quot;, travelMode: &quot;driving&quot;, avoidHighways: false})<br />            dir.setOptions(opts);<br />            <br />            // GMAP Query: From ... To ... <br />            dir.load(&quot;from: &quot; + from.text + &quot; to: &quot; + storeCities.selectedItem.data);<br />            <br />            // Disable query panel<br />            controlPanel.enabled = false;<br />        }<br />            <br />        /**<br />        * Direction Wrong Query (i.e. a city wasn&#39;t found in the db)  <br />        * <br />        */<br />        private function onDirFail(event:DirectionsEvent):void {<br />              Alert.show(&quot;Status: &quot; + event.directions.status);<br />              controlPanel.enabled = true;<br />        }<br />        <br />        /**<br />        * Direction Query SUCCESSFULLY   <br />        * <br />        */<br />        private function onDirLoad(event:DirectionsEvent):void {<br />        	<br />        	// Enable Query Panel<br />        	controlPanel.enabled = true;<br />        	<br />        	// Get Direction object<br />            var dir:Directions = event.directions;<br />            <br />            // Clear previous displayed directions <br />            map.clearOverlays(); <br />            <br />            // Display Directions on Map<br />            var directionsPolyline:IPolyline = dir.createPolyline();<br />            map.addOverlay(directionsPolyline);<br />            var directionsBounds:LatLngBounds = directionsPolyline.getLatLngBounds();<br />            <br />            // Fix map position<br />            map.setCenter(directionsBounds.getCenter());<br />            map.setZoom(map.getBoundsZoomLevel(directionsBounds));<br />       <br />       		// Display Markers (start and destination) <br />            var numRoutes:Number = dir.numRoutes;<br />            var startLatLng:LatLng = dir.getRoute(0).getStep(0).latLng;<br />            var endLatLng:LatLng = dir.getRoute(numRoutes-1).endLatLng;<br />            map.addOverlay(new Marker(startLatLng));<br />            map.addOverlay(new Marker(endLatLng));<br />            <br />            // Display trip info<br />            infoTripTxt.htmlText = dir.summaryHtml;<br />        }<br />            <br />        <br /><br />       ]]&gt;<br />   &lt;/mx:Script&gt;<br />   <br />   <br />   &lt;!--DEBUG KEY: you need to sign up for your own key--&gt;<br />   &lt;maps:Map <br />    id=&quot;map&quot; <br />    key=&quot;ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g&quot; <br />    mapevent_mapready=&quot;onMapReady(event)&quot;<br />    width=&quot;100%&quot; height=&quot;100%&quot;/&gt;<br /><br />    <br /> <br />   &lt;mx:VBox width=&quot;395&quot; height=&quot;200&quot; id=&quot;controlPanel&quot; enabled=&quot;false&quot;<br /> 		backgroundAlpha=&quot;0.8&quot; backgroundColor=&quot;#FFFFFF&quot;&gt;<br /> 		<br />	  &lt;mx:HBox width=&quot;100%&quot;&gt;<br />		   &lt;mx:Label text=&quot;From (write your city):&quot; fontWeight=&quot;bold&quot;/&gt;<br />		   &lt;mx:TextInput<br />		     id=&quot;from&quot;<br />		     text=&quot;Firenze&quot;<br />		     width=&quot;100%&quot; /&gt;<br />	  &lt;/mx:HBox&gt;<br />	  <br />	  &lt;mx:HRule width=&quot;100%&quot; /&gt;<br />	  <br />	  &lt;mx:Label fontWeight=&quot;bold&quot;<br />		  text=&quot;To (select below the store and check the distance):&quot;/&gt;<br />			<br />	  	&lt;mx:HBox width=&quot;100%&quot; height=&quot;100%&quot; verticalAlign=&quot;middle&quot;&gt;<br />		    &lt;mx:List id=&quot;storeCities&quot; width=&quot;150&quot;<br />		    	change=&quot;processForm(event)&quot; height=&quot;121&quot;&gt; <br />		        &lt;mx:Object label=&quot;Milan - Outlet&quot; data=&quot;Milan&quot; /&gt;<br />		        &lt;mx:Object label=&quot;Rome - Boutique&quot; data=&quot;Rome&quot; /&gt;<br />		        &lt;mx:Object label=&quot;Napoli - Outlet&quot; data=&quot;Napoli&quot; /&gt;<br />		        &lt;mx:Object label=&quot;Venezia - Shop&quot; data=&quot;Venezia&quot; /&gt;<br />		        &lt;mx:Object label=&quot;Torino - Outlet&quot; data=&quot;Torino&quot; /&gt;<br />		    &lt;/mx:List&gt;<br />		    <br />		    &lt;mx:TextArea width=&quot;220&quot; height=&quot;60&quot; fontSize=&quot;14&quot; id=&quot;infoTripTxt&quot; <br />		    	backgroundAlpha=&quot;0&quot; borderStyle=&quot;none&quot;/&gt;	<br />		    <br />		&lt;/mx:HBox&gt;<br /><br />  &lt;/mx:VBox&gt;<br /><br />   <br />&lt;/mx:Application&gt;<br /></pre></div><br /><br />]]></description>
      <author>flagers</author>
      <pubDate>Mon, 31 Aug 2009 22:52:20 +0200</pubDate>
      <category>Flex 3.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/4</guid>
   </item>
  </channel>
</rss>
