Quantcast
Channel: Gupta's Galaxy..
Viewing all articles
Browse latest Browse all 10

Google Maps Geocoder in Action..

$
0
0

Ever needed random addresses to be displayed on Google Maps. You can easily achieve the same by using the Google Geocoder. Here is an example..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=YOUR_GMAP_API_KEY" type="text/javascript"></script>
<script type="text/javascript"> 
	//<![CDATA[
 
	var map = null;
	var geocoder = null;
 
	function load()
	{
		if (GBrowserIsCompatible())
		{
			map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(DEFAULT_LATITUDE, DEFAULT_LONGITUDE), DEFAULT_ZOOM);
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			geocoder = new GClientGeocoder();
			convertToLatLng();
		}
	}
 
	function showAddress(address)
	{
		if (geocoder)
		{
			geocoder.getLatLng(
				address,
				function(point)
				{
					if (!point)
					{
						alert(address + " not found");
					} else {
						map.setCenter(point, 13);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						//marker.openInfoWindowHtml(address);
						//showAddress("118 6th Street, Prince Rupert, British Columbia, Canada");
						//showAddress("1600 Park Avenue, Prince Rupert, British Columbia, Canada");
					}
				}
			);
		}
	}
 
	var addresses = [
		'Full Address 1','Full Address2','...'
	];
	var item_html = [
		'First Address Marker HTML','Second Address Marker HTML','...'
	];
 
	var points = [];
 
	function convertToLatLng()
	{
		if (points.length >= addresses.length)
		{
			showPoints();
		} else {
			geocode(addresses[points.length]);
		}
	}
 
	function geocode(address)
	{
		if (geocoder)
		{
			geocoder.getLatLng(
				address,
				function(point)
				{
					points.push(point);
					window.setTimeout(convertToLatLng, 100);
				}
			);
		}
	}
 
	function createMarker(point, code)
	{
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function()
		{
			marker.openInfoWindowHtml(code);
		});
		return marker;
	}
 
	function PopUpMarker(point, address)
	{
		var marker = new Gmarker(point);
		GEvent.addListener(marker, "click", function()
		{
			newwin = window.open(address, 'name', 'width=300,height=200,resizable=1');
		});
		return marker;
	}
 
	function showPoints()
	{
		for (i in points)
		{
			var lat_lng = points[i];
			if (lat_lng)
			{
				map.addOverlay(new GMarker(lat_lng));
				map.addOverlay(createMarker(points[i], item_html[i]));
			}
		}
	}
	window.onload = load;
	window.onunload = GUnload;
 
	//]]>
</script>

Your Ad Here


Viewing all articles
Browse latest Browse all 10

Trending Articles