Menu buttonMENU    UK Free TV logo Archive (2002-)
securesearchsettings

 

 

Click to see updates
To join, leave or change ukfree.tv updates by email, enter your email address here:
 

Google co-ordinate system ... PHP code

There's little documentation to convert Google Maps 3 co-ordinates to WGS84 latitude/longitude, here's my handy little function...

There's little documentation to convert Google Maps 3 co-ordina
published on UK Free TV

Just spent a few annoying hours working this function out.

Google Maps 3 API, the one I'm using to upgrade this site, has a fantastic overlay system, but I was left with Google Maps "x,y,zoom" data in PHP, and I wanted LatLng format to quiz the database. You can do this using the Projection.fromPointToLatLng() Javascript function, but you don't have access to these in the PHP server encironment. So here's the replacement:

function fromPointToLatLng($intX, $intY, $intZoom)
{
$c=pow(2,$intZoom);
$x=360/$c*$intX-180;
$y=180-360/$c*$intY;
$fpLong=$x; 
$fpLat= (2.0*atan(exp($y /180*M_PI))-M_PI/2.0)*180/M_PI;
return array( $fpLat, $fpLong);
}


Such that:

list($fpLat, $fpLong)=fromPointToLatLng($intX, $intY, $intZoom);


For more, see Maps API V3 Overlays - Google Maps JavaScript API V3 - Google Code

All questions
Why has my widescreen TV just made everyone look fat?1
Why are some channels are widescreen others revert to 43 with a black line down 2
If you have several TVs at home do you need separate decoders for each set or is3
Can I use a Freeview box if there is no SCART connector on my TV?4
Why does my widescreen TV only switch during BBC regional programs?5
In this section
Seeing something different? We are doing A/B testing on a new Material Design1
Please share your thoughts about UK FREE TV2
The next 50 things on UK FREE TV. What would you like to see? 3
UK Free TV now uses friendly web addresses4
Best ever emails and improved menus on UK FREE TV5
Use the Knowledge base to find answers to your technical problems6

Comments

Your comment please
Please post a question, answer or commentUK Free TV is here to help people. If you are rude or disrespectful all of your posts will be deleted and you will be banned.







Privacy policy: UK Free Privacy policy.