Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use a <a href="http://pear.php.net/pepr/pepr-proposal-show.php?id=165" rel="nofollow noreferrer">PEAR package</a> or <a href="https://stackoverflow.com/questions/10887692/php-map-projections">this SO answer</a> to calculate your coordinates.</p> <p>The SO thread includes the code for your needs.</p> <hr> <p>Finally, I got a working example for you. (Took a few minutes). I suppose you took <a href="http://www.web-max.ca/PHP/article_1.php" rel="nofollow noreferrer">this</a> article and changed it a bit.</p> <p>At first, you need to calculate the offset of the pin. I took <a href="https://github.com/webpop/jquery.pin/blob/gh-pages/images/pin.png" rel="nofollow noreferrer">this one</a> from a jQuery plugin (I shrinked it down to 50px widthness). This means that you take the x and y coordinate from the tip. Please note that you have to take the upper left point as origin!</p> <pre><code>$pinOffsetX = 19; $pinOffsetY = 42; </code></pre> <p>Now you write down your coordinates. I took the coords for NYC.</p> <pre><code>$long = -74.0059700; $lat = 40.7142700; </code></pre> <p>Load your images. I took <a href="http://en.wikipedia.org/wiki/File:Equirectangular_projection_SW.jpg" rel="nofollow noreferrer">this map</a> to have a large map and check the accuracy.</p> <pre><code>$pin = imagecreatefrompng("pin.png"); $im = imagecreatefromjpeg("map.jpg"); </code></pre> <p>Get the sizes of the images and calculate the coords</p> <pre><code>$scale_x = imagesx($im); $scale_y = imagesy($im); $pinWidth = imagesx($pin); $pinHeight = imagesy($pin); $pt = getlocationcoords($lat, $long, $scale_x, $scale_y); </code></pre> <p>The function was not changed. Now copy the pin onto the map. Notice: I use imagecopy instead of imagecopymerge.</p> <pre><code>imagecopy($im, $pin, $pt["x"] - $pinOffsetX, $pt["y"] - $pinOffsetY, 0, 0, $pinWidth, $pinHeight); </code></pre> <p>The pin Offset has to be subtracted to move the tip onto the location. Output the image (and destroy it!)</p> <pre><code>header ("Content-type: image/png"); imagepng($im); imagedestroy($im); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload