SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    plotting longitude and latitude values on a world map image

    Hi there,

    I've been working on a project recently where I am required to plot points on a flat image of the globe based on a longitude and latitude coordinate that I have stored in a database. I have no problems using Google Maps or Yahoo Maps however Google wants 10 grand to use their mapping commercially. I figured I'd attempt to write one (obviously much simpler) myself. I've read a little bit about converting longitude and latitude to cartesian coordinates however I'm a bit lost. Any help would be greatly appreciated. Thanks!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I did this a few years ago and this is the code that ended up working for me:

    PHP Code:
    function getlocationcoords($lat$lon$width$height) {
       
    $x = (($lon 180) * ($width 360));
       
    $y = ((($lat * -1) + 90) * ($height 180)) - 7;
       return array(
    "x" => round($x), "y" => round($y));

    Where $width and $height are the size of the map image. I recall the -7 being an adjustment because the points seemed offset from their actual locations a few pixels. You might need to work on that with some sample points for your own map unless you can find a better conversion formula.

    And your map should be an accurate Mercator projection.

  3. #3
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, you're the man!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •