I assume that you have the basics for Maps in your code already with your API key.
<head> <script type="text/javascript" href="http://maps.google.com/maps? file=api&v=2&key=xxxxx"> function createMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(37.44, -122.14), 14); } </script> </head> <body onload="createMap()" onunload="GUnload()">
Everything on Google Maps is based on latitude (lat) and longitude (lng).
Thus, to create a simple marker, you simply create a GMarker with lat and lng.
var where = new GLatLng(37.925243,-122.307358); //Lat and Lng for El Cerrito, CA var marker = new GMarker(where); // Create marker (Pinhead thingy) map.setCenter(where); // Center map on marker map.addOverlay(marker); // Add marker to map
However, if you do not want to search Lat and Lng for each city, you can use Google Geo Coder. Here is an example:
var address = "El Cerrito, CA"; var geocoder = new GClientGeocoder; geocoder.getLatLng(address, function(point) { if (point) { map.clearOverlays();
So, I would just create a GLatLng array of each city from GeoCoder and then draw them on a map.
Bernie perez
source share