tags:

views:

345

answers:

2

Hi all

My Google search skills are failing me today. I can add one pin to a Google map using a UK post code. But I can't find how to add multiple pins from a selection of say 100 post codes.

All help apprecaited!

A: 

You may want to check out the following example. I believe it should be self explanatory for you to follow:

<!DOCTYPE html>
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps API Geocoding Demo</title> 
    <script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=false"
            type="text/javascript"></script> 
  </head> 
  <body onunload="GUnload()"> 
    <div id="map_canvas" style="width: 400px; height: 300px"></div> 

    <script type="text/javascript"> 
       var geocoder = new GClientGeocoder();
       var map = new GMap2(document.getElementById("map_canvas"));
       var i;

       var postcodes = [
          'SL59JH',
          'LU13TQ',
          'SR29TD',
          'DA75BQ',
          'EC1V9B'
        ];

       map.setCenter(new GLatLng(54.00, -3.00), 5);

       for (i = 0; i < postcodes.length; i++) {
          geocoder.getLatLng(postcodes[i] + ', UK', function (point) {         
             if (point) {
                map.addOverlay(new GMarker(point));
             }
          });
       }
    </script> 
  </body> 
</html>

Screenshot:

Google Maps API Geocoding Demo

Daniel Vassallo
Hi Daniel, thanks for you example. It appears to work except with certain postcodes. Here is an example array:'HU80QJ','HU74UR','HU53LR','HU53BD','HU74WA','HU106BA','LS110DB'The first three work and the last two do but HU5 3BD and HU7 4WA do not. They work if you do a Google Map search by them selves but not in this example. But if the array just contains those it works?!? Is there a limit on how many postcodes you can do at once?
tonyyeb
Just tried a few more things and found Google Maps to be very inaccurate for converting postcodes using this method. But if I type the postcode straight into maps.google.co.uk it is very accurate. Why is this?
tonyyeb