User:Zocky/Map.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

document.write('<'+'script type="text/javascript" src="'
                + 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAcI9V6O8AJatRG-P1Ao7swBQQcp3yHfYdvNF2yMwM3uUI13B9EhSmf_wGb8aYtyczGT_QitbWCJoQFw'
                + '&action=raw&ctype=text/javascript&dontcountme=s"></'+'script>');
 
document.addEventListener('click',mapOnClick,true);
 
function mapOnClick(e)
{
  var t=e.target;
  if (t.tagName=='A' && t.href.match(/geohack\.php\?params=/))
  {
//    alert(t.href);
    var lat=t.href.replace(/^.*?([\d\.]+)_(([\d\.]+)_)?(([\d\.]+)_)?([SN]).*$/,mapConvert);
    var long=t.href.replace(/^.*?([\d\.]+)_(([\d\.]+)_)?(([\d\.]+)_)?([EW]).*$/,mapConvert);
//    alert(lat+','+long);
 
    document.getElementById('content').innerHTML='<div id="mapMap" style="float:right;width:400px;height:300px;border:solid silver 1px;"></div>' 
    + document.getElementById('content').innerHTML;
 
    if (GBrowserIsCompatible()) 
    {
      var map = new GMap2(document.getElementById("mapMap"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
 
      var point=new GLatLng(lat,long);
      var marker = new GMarker(point);
      map.setCenter(new GLatLng(lat, long), 10);
      map.addOverlay(marker);
      e.preventDefault();
   }
  }
}
 
function mapConvert(p,p1,d2,p2,d3,p3,p4)
{
//  alert(p1+","+p2+","+p3+","+p4);
  c=Math.round((parseFloat(0+p1)+parseFloat(0+p2)/60+parseFloat(0+p3)/3600)*1000000)/1000000;
  if (p4=='W' || p4=='S') return -c;
  return c;
}