Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've been using Google geocoding v3 for about 6 months but all of a sudden it's stopped working (I get a 610 error). It's only stopped in the last week or so.

Then I came across this (see the pink box at the top of the page!): https://developers.google.com/maps/documentation/geocoding/v2/

I've read through all the documentation and not sure where to start!

I'm hoping it's a small change as it's taken a long time to get this far, can anyone help?

See the full site here

This is my code:

<script src="<?php bloginfo('template_directory'); ?>/markerclusterer.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

This is doing the geocoding:

<?php 

require("database.php");
// Opens a connection to a MySQL server
$con = mysql_connect("localhost", $username, $password);

if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("medicom_wp", $con);


    $company = get_the_title();
    $address = get_field('address_line_1');
    $city = get_field('town_/_city');
    $post_code = get_field('post_code');
    $link = get_permalink();
    $type = get_field('kind_of_organisation');

    $sql = sprintf("select count('x') as cnt from markers where `name` = '%s'", mysql_real_escape_string($company));
    $row_dup = mysql_fetch_assoc(mysql_query($sql,$con));
    if ($row_dup['cnt'] == 0) {
        mysql_query("INSERT INTO markers (`name`, `address`, `lat`, `lng`, `type`, `link`) VALUES ('".$company."', '".$address.", ".$city.", ".$post_code."', '0.0', '0.0', '".$type."', '".$link."')");
}
wp_reset_query();


define("MAPS_HOST", "maps.google.com");
define("KEY", "(my key)");

// Opens a connection to a MySQL server
$connection = mysql_connect("localhost", $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die("Can\'t use db : " . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&Key=" . KEY;

// Iterate through the rows, geocoding each address
while ($row = @mysql_fetch_assoc($result)) {
  $geocode_pending = true;

  while ($geocode_pending) {
    $address = $row["address"];
    $id = $row["id"];
    $request_url = $base_url . "&q=" . urlencode($address);
    $xml = simplexml_load_file($request_url) or die("url not loading");

    $status = $xml->Response->Status->code;
    if (strcmp($status, "200") == 0) {
      // Successful geocode
      $geocode_pending = false;
      $coordinates = $xml->Response->Placemark->Point->coordinates;
      $coordinatesSplit = split(",", $coordinates);
      // Format: Longitude, Latitude, Altitude
      $lat = $coordinatesSplit[1];
      $lng = $coordinatesSplit[0];

      $query = sprintf("UPDATE markers " .
             " SET lat = '%s', lng = '%s' " .
             " WHERE id = '%s' LIMIT 1;",
             mysql_real_escape_string($lat),
             mysql_real_escape_string($lng),
             mysql_real_escape_string($id));
      $update_result = mysql_query($query);
      if (!$update_result) {
        die("Invalid query: " . mysql_error());
      }
    } else if (strcmp($status, "620") == 0) {
      // sent geocodes too fast
      $delay += 1000;
    } else {
      // failure to geocode
      $geocode_pending = false;
      echo "Address " . $address . " failed to geocoded. ";
      echo "Received status " . $status . "
\n";
    }
    usleep($delay);
  }
}


?>

This is creating the xml:

<?php
require("database.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'link="' . $row['link'] . '" ';  
  echo 'type="' . $row['type'] . '" ';
  echo '/>';
}
// End XML file
echo '</markers>';
?>

This is generating the map:

   <script type="text/javascript">
    //<![CDATA[

    var customIcons = {
      Academic: {
        icon: 'http://www.teamworksdesign.com/clients/poh/wp-content/themes/default/images/pin-academic.png',
      },
      Business: {
        icon: 'http://www.teamworksdesign.com/clients/poh/wp-content/themes/default/images/pin-business.png',
      },
      Clinical: {
        icon: 'http://www.teamworksdesign.com/clients/poh/wp-content/themes/default/images/pin-clinical.png',
      },
      Government: {
        icon: 'http://www.teamworksdesign.com/clients/poh/wp-content/themes/default/images/pin-government.png',
      },  
      Charity: {
        icon: 'http://www.teamworksdesign.com/clients/poh/wp-content/themes/default/images/pin-charity.png',
      }                     
    };

    function load() {
      var cluster = [];
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(52.375599, -3.471680),
        zoom: 7,
        mapTypeId: 'roadmap'
      });
      var infowindow = new google.maps.InfoWindow();
      var min = .999999;
      var max = 1.000002;

      // Change this depending on the name of your PHP file
      downloadUrl("<?php bloginfo('stylesheet_directory'); ?>/phpsqlajax_genxml.php ", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var type = markers[i].getAttribute("type");

          var offsetLat = markers[i].getAttribute("lat") * (Math.random() * (max - min) + min);
          var offsetLng = markers[i].getAttribute("lng") * (Math.random() * (max - min) + min);

          var point = new google.maps.LatLng(offsetLat, offsetLng);
          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          google.maps.event.addListener(marker, 'click', (function(marker, i) {
                        return function() {
                            var name = markers[i].getAttribute("name");
                            var address = markers[i].getAttribute("address");
                            var type = markers[i].getAttribute("type");
                            var link = markers[i].getAttribute("link");
                            var html = "<b>" + name + "</b> <br/>" + type + "<br/><br/><a href='" + link + "'>View profile</a>";
                            infowindow.setContent(html);
                            infowindow.open(map, marker, html);
                            // infowindow.setContent(html);
                            // infowindow.open(map, marker);
                        }
                    })(marker, i));
          cluster.push(marker);
        }
        var mc = new MarkerClusterer(map,cluster);
      });
    }

    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}

    //]]>
share|improve this question

2 Answers 2

610 = G_GEO_BAD_KEY

The given key is either invalid or does not match the domain for which it was given.

https://developers.google.com/maps/documentation/javascript/v2/reference#GGeoStatusCode

Check with IT/ISP that the IP has not changed (request a Static IP for your IT/ISP).

You can request another API Key (check on your dev/test server first)

Temporary workaround V3 does NOT require an API key (though sensor=*true_or_false*) is

example: http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false

You will be limited to 1500 geocodes requests per 24 hours.

https://developers.google.com/maps/documentation/geocoding/

share|improve this answer
    
As per Google saying they've changed the way it geocodes. I checked the key but it doesn't seem to be that. I'm not going to be hitting the limit so that's fine. I tried without the key but I still hit a problem. I think it's to do with the url, I tried this but no luck: define("MAPS_HOST", "maps.googleapis.com"); $base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?"; $request_url = $base_url . "address=" . urlencode($address) . "&sensor=false&Key=" . KEY; –  Rob Mar 15 '13 at 14:09
    
remove "&Key=" from "&sensor=false&Key=" for xml try maps.googleapis.com/maps/api/geocode/… (works on our setup) –  Mapperz Mar 15 '13 at 14:30
    
I gave that a go but still no luck. It enters the marker into the database but with 0 & 0 as long/lat. –  Rob Mar 15 '13 at 14:35
    
This is my xml if that helps - teamworksdesign.com/clients/poh/wp-content/themes/default/… –  Rob Mar 15 '13 at 14:42
    
Just called maps.googleapis.com/maps/api/geocode/… in our setup and it got ROOFTOP (the best) Geocode back - I reformatted address as your see - so must be your php code parsing incorrectly. –  Mapperz Mar 15 '13 at 14:54

The URL http://" . MAPS_HOST . "/maps/geo?output=xml is for the old Google Maps v2 geocoding api. Google discontinued the v2 geocoding api on March 8th 2013. Please read https://developers.google.com/maps/documentation/geocoding/v2/ for more information (red box on top of this page).

I would recommend to move to the v3 geocoding api as written on the other comments. The restrictions are 2'500 geocoding requests per 24h per ip address (of the server), and currently only approx. 200 requests in a short intervall.

V3 geocoding requests look like http://" . MAPS_HOST . "/maps/api/geocode/" . More information can be found at https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.