Google Maps API Tutorial -2


At last article I talked about Google Map basic concepts. At map you can show different control options to pan/zoom map, showing driving directions, map types etc.
Generally used controls are -
GLargeMapControl - a large pan/zoom control used on Google Maps. Appears in the top left corner of the map by default.
GSmallMapControl - a smaller pan/zoom control used on Google Maps. Appears in the top left corner of the map by default.

  1.  
  2. var map = new GMap2(document.getElementById("map"));
  3. map.addControl(new GSmallMapControl());
  4.  

These controls can be positioned on map by adding an optional second parameter to method GControlPosition.

  1.  
  2. var map = new GMap2(document.getElementById"map"));
  3. var mapTypeControl = new GMapTypeControl();
  4. var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
  5. map.addControl(mapTypeControl, topRight);
  6.  

You can even modify markup of these standard controls but thats not the scope of our article :). More information on google map controls can be found at http://code.google.com/apis/maps/documentation/controls.html

At last article I mentioned how to add markers to the map. Interestingly we can change icons for the markup. Instead of default Default marker you can use same fancy icons like or . This is also helpful to show different icons for different type of markers. E.g. if you are showing locations of users, subscribers, agents, resellers etc. at your site, you can use different icon representing each of this user type on map.

  1.  
  2. // Create a base icon for all of our markers that specifies the
  3. // shadow, icon dimensions, etc.
  4. var baseIcon = new GIcon(G_DEFAULT_ICON);
  5. baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
  6. baseIcon.iconSize = new GSize(20, 34);
  7. baseIcon.shadowSize = new GSize(37, 34);
  8. baseIcon.iconAnchor = new GPoint(9, 34);
  9. baseIcon.infoWindowAnchor = new GPoint(9, 2);
  10.  
  11. // Create icon for this point using our icon class
  12. var letteredIcon = new GIcon(baseIcon);
  13. letteredIcon.image = "http://www.google.com/mapfiles/markerA.png";
  14.  
  15. // Set up our GMarkerOptions object
  16. markerOptions = { icon:letteredIcon };
  17. var marker = new GMarker(point, markerOptions);
  18.  
Have you liked it? Why not help me by sharing this :
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

Leave a comment

Your comment