Google services

From Code Trash
Jump to: navigation, search

Google Map

Map API Key for localhost

<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAaxSYP2CDcDAus5lPzh_b0xSezU1S2HSJoqv5Iheu5g210VUkFxRXIAAz_VQ4UGFLKZpa6-KALRuAIQ"
type="text/javascript"></script>

Simple google map - using address

Show a map of an address by converting the address to its lat lng. Create a information window for that marker so that when an user clicks on the marker a baloon info opens


var la, lo, point
 
function mapi(address)
{
    var geocoder = new GClientGeocoder ();	
 
    geocoder.getLatLng (address, function (point)
    {
	if(!point)
	{
		document.getElementById('maps').innerHTML = "<p>Invalid Address</p>";
		return;
	}
        la = point.lat();
        lo = point.lng();
 
 
		if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("maps"));
 
		map.addControl(new GLargeMapControl());
	    map.addControl(new GMapTypeControl(3));	
        map.setCenter(new GLatLng(la,lo), 17,G_HYBRID_MAP);	
		var pt = new GMarker(new GLatLng(parseFloat(la),parseFloat(lo))	)
	    map.addOverlay(pt);		  	
 
        GEvent.addListener(pt, "click", function() 
		{ 
			map.openInfoWindow(map.getCenter(),"<p style='color:black;'>aiyoo aiyoo</p>");
		}); 
      }		
    });
 
}


<div id='maps' style='width:500px; height:300px;'></div>


Weather API

Use this XML file for output in Fahrenheit:
http://www.google.com/ig/api?weather=Drammen
And this one for Celsius:
http://www.google.co.uk/ig/api?weather=Drammen