6 Replies Latest reply on Nov 8, 2011 2:13 PM by kraikit

    How can i get LatLng out of a database to work in maps?

    Gerard1982

      Hello,

      I am struggeling with a problem with a project of mine for several months now.

      In Flash Builder i have a Flex Mobile Project with a list and on click, i want a map to show up.

      What i try to do is, get the coordinates from a database and transport it to a map on a mobile device.

      This is my sample code :

       

      protected function onMapReady(event:MapEvent):void

                                    {

       

                                              map.setCenter(new LatLng(53.207208,5.913611), 14, MapType.NORMAL_MAP_TYPE);

                                              var markerA:Marker = new Marker( new LatLng(53.207208,5.913611)  );

                                              map.addOverlay(markerA);

                                              map.addControl(new ZoomControl());

                                              map.addControl(new PositionControl());

                                              map.addControl(new MapTypeControl());

                                              startGPS();

       

                                    }

       

      I get my lat and lng from the database and push it to the next view.

      On this view i  get the data as {data.lat} and  {data.lng}.

      If i put this in a textfield it works:    <s:Label y="100" left="10" right="10" text="{data.lat},{data.lng}"/>

       

      But if i try to put it in a new LatLng() like this: new LatLng({data.lat},{data.lng}), the marker doen't show in the map and i have errors in FlashBuilder.

      Maybe my approach is wrong, so if you know a better way to do it i am open to it.

      Can you help me to solve this problem.

       

      I would be very gratefull if you would help me.

       

      Sincerely, Gerard Weijer

        • 2. Re: How can i get LatLng out of a database to work in maps?
          kraikit

          If you're in ActionScript I don't think you need the curly braces, i.e. it should just simply be

           

          var latLng:LatLng = new LatLng(Number(data.lat), Number(data.lng));

           

          (note the casting to Number)

           

          -- Tom

          • 3. Re: How can i get LatLng out of a database to work in maps?
            Gerard1982 Level 1

            Thank you very much!!!.. It works..

             

            But now i have 2 markers and i want the route to be shown as an blue line in between the markers...

             

            This code produces the 2 markers:

             

            protected function onMapReady(event:MapEvent):void

                                          {

             

                                                    map.setCenter(new LatLng(data.lat,data.lng), 14, MapType.NORMAL_MAP_TYPE);

                                                    var markerA:Marker = new Marker( new LatLng(data.lat,data.lng) );

                                                    map.addOverlay(markerA);

                                                    map.addControl(new ZoomControl());

                                                    map.addControl(new PositionControl());

                                                    map.addControl(new MapTypeControl());

                                                    startGPS();

             

                                          }

                                          protected function startGPS():void {

                                                    if(Geolocation.isSupported){

                                                              geoLocation = new Geolocation();

                                                              if(geoLocation.muted){

             

                                                              }

                                                              geoLocation.setRequestedUpdateInterval(3000);

                                                              geoLocation.addEventListener(GeolocationEvent.UPDATE, handleLocationRequest);     

                                                    } else {

                                                             // turn on gps!

             

                                                    }

                                          }

             

                                          private function handleLocationRequest(event:GeolocationEvent):void {     

                                                    map.setCenter(new LatLng(event.latitude,event.longitude));   

             

                                                    var markerB:Marker = new Marker(

                                                              new LatLng(event.latitude,event.longitude));

                                                    map.addOverlay(markerB);

             

                                          }

            • 4. Re: How can i get LatLng out of a database to work in maps?
              kraikit Level 2

              I'm not sure what mapping API you are using but if you want to overlay a route you'll probably want to use their functionality to do so. Just as one example, the Google Maps ActionScript API Directions object contains the polyline that can be used to draw the line between the two points:

               

              http://code.google.com/apis/maps/documentation/flash/reference.html#Directions

               

              The MapQuest API also has functionality to draw routes on the map.

               

              -- Tom

              Flex SDK Engineer

              • 5. Re: How can i get LatLng out of a database to work in maps?
                Gerard1982 Level 1

                i am using the google maps API.

                but i dont know how and where to put the polyline codes in my codes...

                • 6. Re: How can i get LatLng out of a database to work in maps?
                  kraikit Level 2

                  Hi,

                   

                  Sorry, I haven't played around with polylines using the Google API yet, but from the examples listed it looks pretty straightforward:

                   

                  http://code.google.com/apis/maps/documentation/javascript/overlays.html#Polylines

                   

                  Best of luck,

                   

                  -- Tom

                  Flex SDK Engineer