14 Replies Latest reply on Nov 24, 2008 8:42 AM by logeye

    x and y into Latitude and longitdue


      How do i convert x and y of a movie in longitude and latitude? the dimension of the movie is w= 1004 and h = 418 where te map movie clip dimension is w= 852 an h= 418. The movie clip is right aligned to he stage.

        • 1. Re:  x and y into Latitude and longitdue
          Ned Murphy Adobe Community Professional & MVP
          You probably need the help of someone who works in the mapping realm rather than someone here, but you might get lucky and find someone who's dealt with coding this.
          • 2. Re:  x and y into Latitude and longitdue
            Rothrock Level 5
            It depends upon which projection your map is using. This part is not open for debate. Since the world is round it can't just be simply placed on a flat surface. You need some way of unwrapping if flatly.

            The most common method is the Mercator projection.


            They give the equations about halfway down the page. I've used this before and it worked well.

            Otherwise you will need to find out what projection your map uses and the search for its equations.
            • 3. Re:  x and y into Latitude and longitdue
              logeye Level 1
              Here’s a quick way, depending on what you want. The assumptions are:

              You are using a cylindrical projection, parallels and meridians are straight and perpendicular to each other.
              The dimensions of your movie are the dimensions of your stage.

              I made a movie clip with an instance name of map and placed it on the stage aligned with the right of the stage.

              The mouse cursor position gives you the Longitude of the map.

              There is a dynamic text field on the stage with the variable name stagePosit. This gives the x coordinate of the mouse cursor on the main stage.

              There are two dynamic text fields located within the map movieclip. The variable names are mapLon (Gives the Longitude of the map)
              and mapPosit. (gives the x position of the map coordinate system.

              This code in on in the first frame of the main time line. It is NOT in the movie clip, map.

              For my map the right most Longitude is 42degrees west longitude.
              The left most Longitude is 44 degrees 10 minutes = (44.1666666) 10 minutes is 10/60 or 1/6.

              As you move the cursor over the map you should get 3 things:
              The Longitude of the map and the x position of the main stage and map movie clip.

              Hope this helps. It worked for me. Similar methods can be used for Latitude.

              this.onMouseMove = function() {
              this.map.mapPosit = map._xmouse;
              this.stagePosit = this._xmouse;
              // Left most Longitude of your map
              lLon = 44.16666666666;
              // right most longitude of your map
              rLon = 42;
              // ΔLon
              deltaLon = rLon-lLon;
              convert_p2d = -deltaLon/this.map._width;
              this.map.mapLon = lLon-(this.map.mapPosit)*(convert_p2d);
              • 4. Re:  x and y into Latitude and longitdue
                Rothrock Level 5
                logeye - if the map is a Mercator projection (most likely) then similar methods won't work for latitude. In fact any cylinderical projection will have distortion in one of the directions it all depends upon the original orientation of the cylinder.

                The OP will need to use one of the forms of the equation given for y on the link above. A bit more complex than the x (longitude) equation, but fairly simple.
                • 5. Re:  x and y into Latitude and longitdue
                  .:}x-=V!P=-x{:. Level 3
                  i just went through this but backwards, I had to convert Lon/Lat to X/Y. Wow that was a headache. the best way could get working was taking three points and using those values to calculate the difference in both values. Like guessing the X/Y for LA and DC and finding the distance in X and then the Lon/Lat of LA and DC and finding the distance in Lon then doing the same for like Yellowstone and Dallas to find difference in Y and Lat. then using the difference in deg per pixel..... ahhh my head is spinnning again.
                  • 6. Re:  x and y into Latitude and longitdue
                    Rothrock Level 5
                    If it was a mercator then the equations on that page give you inverse as well.

                    If you need to calculate the distance between points a mercator doesn't preserve distances. But somewhere at home I have the equation for figuring the distance between two points on the earth.
                    • 7. Re:  x and y into Latitude and longitdue
                      .:}x-=V!P=-x{:. Level 3
                      Ya im not a math guy but how do you get sinh and tanh I only see sin and tan in the Flash math classes.
                      • 8. Re:  x and y into Latitude and longitdue
                        Rothrock Level 5
                        Those are the hyperbolic trig functions and flash doesn't have them built in. There are ways, but I would suggest using one of the version of the formula that doesn't include a hyperbolic function.
                        • 9. Re:  x and y into Latitude and longitdue
                          Ayush.Jain Level 1
                          Hi logeye,

                          Thanks for the response. The code you have provided is working for to get the longitude and now i am stuck with latitude. Am too bad at maths and logic, so am looking forward if you can help me that too.

                          And thanks to all for responding. I know i will always get help here.

                          • 10. Re:  x and y into Latitude and longitdue
                            Ayush.Jain Level 1

                            just came to know i need to call longitude and latitude from xml and then postion the movie clip on to the stage. That means i need to convert Lat and Long in x and y. Can we use the same formula to do this?

                            • 11. Re:  x and y into Latitude and longitdue
                              logeye Level 1

                              I'm glad the math is working. It is an approximation.

                              How accurate do you need to be? If you stay below 35degrees latitude or so, similar math should be useful for calculating latitude. Rothrock is right, the further you get away from the equator, the less accurate my method is for latitude.

                              When you say you are calling Lat/Long from and XML file and then positioning the map on the stage, does that mean your map movie clip contains a map that is larger than the map movieclip and you can move the map around under a mask to line up with a given set of Lat/Long from the xml file? Or do you have a series of maps that are called into the map movie clip depending onwhich map matchesthe Lat/Lonfg in the xml file?

                              Where's Christopher Columbus when you need him. He was an expert in spherical geometry and cartography.
                              • 12. Re:  x and y into Latitude and longitdue
                                logeye Level 1
                                What kind of map do you have?
                                • 13. Re:  x and y into Latitude and longitdue
                                  Ayush.Jain Level 1
                                  Hi Logeye,

                                  I don't need exact location but approximate result is fine with me. I was able to resolve the Latitude as per your longitude formula.

                                  I am creating a map with zoom function which will display certain places around the world. I have created a movie clip with pointer graphic and my idea is to duplicated the movie clip and place them over the map as per the data from the XML file. The XML file has Coordinates in Longitude and latitude format.

                                  I have put Zoom functionality on the map and want to know whether it is possible to place the pointer movie clip at the same place when I zoom the map.

                                  • 14. Re:  x and y into Latitude and longitdue
                                    logeye Level 1

                                    It’s good the initial math is working for you. I’ve only used XML once so I may not be able to help with that. Others are more versed with that than me.

                                    Let me rephrase what you have stated to see if I understand correctly.

                                    You have a large scale map, probably the map of the world. Using the Lat/Long data from the XML file you duplicate and populate the map with your pointer movieclip. This you have completed.

                                    I assume you click on a location to cause the map to zoom (scale?) in on that area. Once zoomed in the pointer graphic should still be displayed in the same relative location as before.

                                    Do you zoom in so close that only one movieclip graphic is displayed or do you just zoom in a little so multiple movieclip graphics are still displayed?? If only one graphic is displayed, zoom the the center of the area you are showing and put the graphic in the center of the map. If you still have multiple graphics showing, that will require a different approach.

                                    Wishing you the best,