PHP Map projections

前端 未结 2 1155
臣服心动
臣服心动 2021-01-17 04:46

I have Googled myself to death.. I am attempting to write 2 php functions that will return X and Y from Lat and Long, in both Mercator and flat non-projected (grid) maps. Pr

2条回答
  •  野的像风
    2021-01-17 05:11

    This presumes your lat/long coords are decimal values, and don't change direction from north/south or east/west within the visible range of the map. If they do, such values should be kept to a single format, and made negativel (eg: 1.0 S would become -1.0 N)

    First you'd set the following variables, either finding them with PHP or if you know them already in the script:

    $width=//width of image
    $height=//height of image
    
    $long_at_left=//Longitude of left-hand coordinates
    $long_at_right=//Longitude of right-hand coordinates
    $lat_at_left=//Latitude of left-hand coordinates
    $lat_at_right=//Latitude of right-hand coordinates
    
    $target_long=//Longitude you want to find
    $target_lat=//Latitude you want to find
    

    Then use:

    $xtarget=$target_long-$long_at_left;
    $ytarget=$target_lat-$lat_at_top;
    
    $xdist=$long_at_left-$long_at_right;
    $ydist=$lat_at_top-$lat_at_bottom;
    
    $x=round(($xtarget/$xdist)*$width); //Percentage of distance times width
    $y=round(($ytarget/$ydist)*$height); //Percentage of distance times height
    

    Or something of that form should do the trick.

提交回复
热议问题