Geocoding With PHP and the Google Maps API

figure-01

Geocoding with PHP and the Google Maps API

Quentin Zervaas

Introduction

Geocoding is the process of finding the longitude and latitude of a given address or location. The Google Maps service gives developers and web site owners free access to their geocoder, both using the Google Maps JavaScript API, as well as using the web service. In this article I will show you how to access the geocoder web service using PHP so that it can be used in your own applications.

There are many applications for a geocoder and having access to a free, reliable and frequently updated geocoder is a huge help in web application development. Some examples of where a geocoder can be useful include:

  • Plotting a user-submitted address on a map (such as a property owner listing their house on a real estate web site).
  • Discovering the longitude and latitude so calculations can be performed (such as a finding other sets of coordinates within a given distance).
  • Verifying addresses before shipping orders from your ecommerce store.
  • Retrieving the properly formatted address string for the given location. This is very useful when you consider how inconsistent users can be when entering their address.

When using Google Maps to display maps on your web site, it is easy to access the JavaScript based geocoder, however this isn’t always an adequate solution, especially when it comes to accessibility.

For example, if your application saves coordinates based on a user-submitted address using the JavaScript geocoder, then this solution will not work for users who have JavaScript disabled. To overcome this we can use the web service instead, meaning all requests to the geocoder are performed on the server side.

In this article we will develop several PHP 5 classes that will make it easy to query the geocoder and access the response.

Beginning with Google Maps

While we are not specifically dealing with the display of maps on our web sites in this article, we still need to be familiar with the Google Maps API. All documentation for the API can be found at http://code.google.com/apis/maps/index.html.

The first thing that you must do is to create an API key for your web site. This is used to identify all requests to the API. You can receive a free key by agreeing to the terms and entering your web site URL at http://code.google.com/apis/maps/signup.html.

At time of writing this article, the limit on geocoder requests is 15,000 per day, which will hopefully be sufficient for your needs. As mentioned later in this article, you are encouraged to cache geocoder data in your own application wherever possible.

Once you have an API key then you are able to access the geocoder. In the rest of this article we will cover how to use the geocoder, which is based on the documentation at http://code.google.com/apis/maps/documentation/services.html#Geocoding_Direct.

Performing a Geocoder Request

When you perform a geocoder request, you can specify which output type to use. The available options are JSON, XML, KML and CSV. In this article we will be requesting and handling XML data.

Note: KML (which stands for Keyhole Markup Data) is an XML format that was developed for use with Google Earth (formerly called Keyhole). The KML and XML output from the geocoder are identical; however the HTTP mime type that is sent differs for the two types.

Although JSON data is typically used within JavaScript code, we could also easily use this data instead of the XML response. To turn the data into a PHP array you could use the json_decode() function (available since PHP 5.2.0). We will be using SimpleXML in this article to read geocoder data, but to use JSON instead would be a trivial change.

To perform a geocoder request, a HTTP get request is sent to http://maps.google.com/maps/geo. There are three URI parameters that must be specified in this request:

  • q – The address or location that you want to geocoded.
  • key – This is the Google Maps API key that you created earlier in this article.
  • output – This the output format for the response (as discussed above). The values that can be used are json, xml, kml or csv.

For example, if you wanted to find the coordinates of The White House (located at 1600 Pennsylvania Avenue, Washington, DC), you would request the following URL:

http://maps.google.com/maps/geo?q=1600+pennsylvania+ave+washington+dc&output=xml&key=123456

Note: Remember to substitute your own API key in the request URL.

The precise address string you send in the query is not critical – it simply needs enough data in it to identify the location you’re after (that is, it should not be ambiguous).

Understanding the Geocoder Response

After you send the geocoder request, you will receive a response back in the format you specified. For example, if we request the address of the White House (using the URL http://maps.google.com/maps/geo?q=1600+pennsylvania+ave+washington+dc&output=xml&key=123456), we will receive the following response XML (note that I have indented it to make it more easily readable):

<?xml version=”1.0″ encoding=”UTF-8″?>

<kml xmlns=”http://earth.google.com/kml/2.0″>

<Response>

<name>1600 pennsylvania ave washington dc</name>

 

<Status>

<code>200</code>

<request>geocode</request>

</Status>

 

<Placemark id=”p1″>

<address>1600 Pennsylvania Ave NW, Washington, DC 20006, USA</address>

<AddressDetails Accuracy=”8″ xmlns=”urn:oasis:names:tc:ciq:xsdschema:xAL:2.0″>

<Country>

<CountryNameCode>US</CountryNameCode>

<AdministrativeArea><AdministrativeAreaName>DC</AdministrativeAreaName>

<SubAdministrativeArea>

<SubAdministrativeAreaName>District of Columbia</SubAdministrativeAreaName>

<Locality>

<LocalityName>Washington</LocalityName>

<Thoroughfare>

<ThoroughfareName>1600 Pennsylvania Ave NW</ThoroughfareName>

</Thoroughfare>

<PostalCode>

<PostalCodeNumber>20006</PostalCodeNumber>

</PostalCode>

</Locality>

</SubAdministrativeArea>

</AdministrativeArea>

</Country>

</AddressDetails>

 

<Point>

<coordinates>-77.036655,38.898774,0</coordinates>

</Point>

 

</Placemark>

</Response>

</kml>

Within the Response tag, there are three key elements:

  • name: This is the search query sent to the geocoder
  • Status: This includes the response code of the request, which is a simple way to determine what actually happened when the request was performed. The possible response codes are as follows:
    • 200: Successful request (at least one placemark was returned).
    • 400: Bad request (the server was unable to understand the request).
    • 500: Server error (an unknown internal error occurred).
    • 601: Missing query. This means the q parameter was not specified (or was an empty string).
    • 602: Unknown address. This means that the request was performed but no placemarks were found.
    • 603: Unavailable address. The given address could not be returned due to legal or contractual reasons.
    • 610: An invalid Google Maps API key was specified.
    • 620: Too many queries have been performed using the given API key.
  • Placemark: Assuming that the status code was 200, there will be at least one Placemark element in the returned XML. This element contains all the geocoder information for the given address or location.

Once we have a valid response, we can loop over each placemark and save the data accordingly.

The first useful item of information included in each placemark is a formatted address. This is extremely useful since the data is much more consistent and means you don’t need to rely on user-submitted data. If you look at the above example, we submitted 1600 pennsylvania ave washington dc as the request string and received 1600 Pennsylvania Ave NW, Washington, DC 20006, USA as the formatted address.

Next is the AddressDetails element, which uses the Extensible Address Language (xAL). This element has an attribute called Accuracy, which specifies the accuracy level of the returned placemark. The possible values for Accuracy are:

  • 0: Unknown
  • 1: Country
  • 2: Region
  • 3: Sub-region
  • 4: Town
  • 5: Postcode
  • 6: Street
  • 7: Intersection
  • 8: Address

In our example the accuracy level is 8, meaning it is the highest level of accuracy. With the code we develop in this article you will be able to test the different accuracy levels (for example, entering Australia as the query term will return an accuracy of 1).

The other elements within AddressDetails break down each part of the complete address into their corresponding categories, marked-up according to the xAL specification.

Finally, each placemark contains a Point element. This element contains a comma-separated string where the first value is the longitude; the second value is the latitude; and the third value is the elevation (typically not used). Thus in our example the longitude is 77.036655 and the latitude is 38.898774. This precision (that is, six decimal points) is accurate to 4 inches (11 centimeters).

Accessing the Geocoder Data Using SimpleXML

Now that we know how to retrieve a geocoder response and what the returned XML actually means, we can parse the XML so we can use the data as required.

To parse the XML we are going to use SimpleXML, which as its name suggests, makes the use of XML in PHP very simple. SimpleXML has been available natively in PHP since PHP 5.

To read the values in an XML file, all we need to do is instantiate the SimpleXMLElement class, passing to its constructor the XML string we want to parse. Listing 3 shows an example of how this is achieved.

<?php

$str = ‘<kml> <Response> …. </Response> </kml’; // sample XML file

$xml = new SimpleXMLElement($str);

?>

Once you have the SimpleXMLElement object, you can access any element in the XML file just as you would with normal PHP object properties. Returning the geocoder response from earlier in this article, you can access the status code of the request using the following code:

<?php

$xml = new SimpleXMLElement($geocoderResponse);

echo $xml->Response->Status->code;

?>

In actual fact, the type of $xml->Response->Status->code is another instance of SimpleXMLElement. Therefore, you should really be casting this value to the type required (such as a string or an integer).

Listing 5 shows an example of reading the status code and ensuring the request completed successfully (remember that a response code of 200 means the request was successful).

<?php

$xml = new SimpleXMLElement($geocoderResponse);

$status = (int) $xml->Response->Status->code;

 

if ($status == 200) {

// geocoder request completed successfully

}

?>

We now know how to read the values within XML tags, but some data will be held in attributes rather than as tag values. One such example is the Accuracy attribute for each Placemark element. To access an attribute when using SimpleXML you treat its parent element as an array.

Listing 6 shows how we can loop over each placemark in the response and then access its Accuracy value accordingly, as well as outputting the properly formatted address.

<?php

$xml = new SimpleXMLElement($geocoderResponse);

 

foreach ($xml->Response->Placemark as $placemark) {

$accuracy = (int) $placemark->AddressDetails[‘Accuracy’];

 

if ($accuracy == 8) {

// address level accuracy

}

 

echo $placemark->address . “\n”;

}

?>

At this point we have covered all of the base knowledge required to query the geocoder, understand the response, and read specific values from the returned XML using SimpleXML.

We will now implement a fully functioning geocoder using PHP 5 that combines everything we have covered so far in this chapter.

Creating the Geocoder Class

We will now implement a PHP 5 solution for easily using the Google geocoder. We will achieve this by creating three classes:

  • Geocoder: This will be the class used to perform the geocoder request and to read the response.
  • Placemark: This class will be used to hold each returned location from the geocoder.
  • Point: We will store longitude and latitude data using this class.

While you could implement a solution using a single class, I have chosen to do as just outlined so you can easily drop it in to your own applications. It also hopefully demonstrates some good principles for object oriented development in PHP.

Let’s begin by creating the Geocoder class. This class will contain a method called lookup(), to which the address to be geocoded is accepted as the only argument. From this method an array of Placemark objects will be returned.

The code for this class should reside in a file called Geocoder.php. The complete file is available from the article file downloads section.

Listing 7 shows the beginning of this class. Firstly we define the URL of the geocoder (which we learned earlier was http://maps.google.com/maps/geo). We then define a number of constants to correspond to each of the status codes that can be returned. Using constants makes the code much easier to read and maintain. For consistency we use the same names as the JavaScript API does, documented at http://code.google.com/apis/maps/documentation/reference.html#GGeoStatusCode.

This listing concludes by defining the class constructor, which accepts your Google Maps API key as its only argument.

<?php

class Geocoder

{

public static $url = ‘http://maps.google.com/maps/geo’;

 

const G_GEO_SUCCESS             = 200;

const G_GEO_BAD_REQUEST         = 400;

const G_GEO_SERVER_ERROR       = 500;

const G_GEO_MISSING_QUERY       = 601;

const G_GEO_MISSING_ADDRESS     = 601;

const G_GEO_UNKNOWN_ADDRESS     = 602;

const G_GEO_UNAVAILABLE_ADDRESS = 603;

const G_GEO_UNKNOWN_DIRECTIONS = 604;

const G_GEO_BAD_KEY             = 610;

const G_GEO_TOO_MANY_QUERIES   = 620;

 

protected $_apiKey;

 

public function __construct($key)

{

$this->_apiKey = $key;

}

 

// other code

}

?>

As mentioned above, we will be implementing a method called lookup(), used to return an array of Placemark objects. Internally, as we will soon see this method will be responsible for reading the geocoder response. We firstly need a way to retrieve that response, which we will do using the performRequest() method.

Listing 8 shows the code for performRequest(), which accepts the location to geocoder as its first argument and the output type as its second argument. While we will only be using the XML output, coding the method in this manner allows you to easily reuse it for other output types (such as JSON) if required.

This method uses the PHP Curl functions to perform the HTTP request. In order to retrieve the response as a string, the CURLOPT_RETURNTRANSFER option must be set to true. Not doing so would result in the response being output directly to your browser.

<?php

class Geocoder

{

// other code

 

public function performRequest($search, $output = ‘xml’)

{

$url = sprintf(‘%s?q=%s&output=%s&key=%s&oe=utf-8’,

self::$url,

urlencode($search),

$output,

$this->_apiKey);

 

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

curl_close($ch);

 

return $response;

}

 

// other code

}

?>

We can now implement the lookup() method, which is shown in Listing 9. This method begins by retrieving the XML response using the performRequest() method. An instance of SimpleXMLELement is then created using this response.

Next we read the returned status value to determine the response. The way I have coded this is to assume a request was successful if the status code is G_GEO_SUCCESS, G_GEO_UNKNOWN_ADDRESS or G_GEO_UNAVAILABLE_ADDRESS. The latter two, while indicating a response that includes no placemarks, still indicate that a search successfully occurred (that is, the request was valid, as was the API key), so we return an empty array (that is, no placemarks).

Note: Technically speaking, G_GEO_UNKNOWN_ADDRESS and G_GEO_UNAVAILABLE_ADDRESS correspond to the same value. I have included both for completeness. If Google decide to use a different value for one of these, our code would only need to be updated in the definitions at the start of the class.

If the status code is G_GEO_SUCCESS, we loop over the returned placemarks and create a Placemark object for each one. Each Placemark object is added to the return array. We will cover the FromSimpleXml() method when we implement the Placemark class. For now, all you need to know is that it returns an instance of Placemark.

For every other status code, we assume some kind of error occurred. To deal with this error, we throw an exception in which the returned status code is included in the exception message.

<?php

class Geocoder

{

// other code

 

public function lookup($search)

{

$response = $this->performRequest($search, ‘xml’);

$xml     = new SimpleXMLElement($response);

$status   = (int) $xml->Response->Status->code;

 

switch ($status) {

case self::G_GEO_SUCCESS:

require_once(‘Placemark.php’);

 

$placemarks = array();

foreach ($xml->Response->Placemark as $placemark)

$placemarks[] = Placemark::FromSimpleXml($placemark);

 

return $placemarks;

 

case self::G_GEO_UNKNOWN_ADDRESS:

case self::G_GEO_UNAVAILABLE_ADDRESS:

return array();

 

default:

throw new Exception(sprintf(‘Google Geo error %d occurred’, $status));

}

}

}

?>

This now completes the Geocoder class. If you want to use the performRequest() method on its own, you can now do so, however we must first implement the Placemark class before you can use the lookup() method.

Listing 10 shows the code you can use to test out the performRequest() method. Remember to use your own API key when instantiating the Geocoder class.

<?php

require_once(‘Geocoder.php’);

 

$address = ‘1600 Pennsylvania Ave Washington DC’;

$geocoder = new Geocoder(‘your key’);

 

$xml = $geocoder->performRequest($address, ‘xml’);

$json = $geocoder->performRequest($address, ‘json’);

$csv = $geocoder->performRequest($address, ‘csv’);

?>

<html>

<head>

<title>Testing the performRequest() method</title>

</head>

<body>

<div>

<h1>Testing the performRequest() method</h1>

 

<h2>Address: <?php echo $address ?></h2>

 

<h3>XML</h3>

<?php echo htmlSpecialChars($xml) ?>

 

<h3>JSON</h3>

<?php echo htmlSpecialChars($json) ?>

 

<h3>CSV</h3>

<?php echo htmlSpecialChars($csv) ?>

</div>

</body>

</html>

Creating the Placemark Class

We will now implement the Placemark class, which is used to hold information about a single location. Rather than storing all of the separate address parts that are returned from the geocoder, we will simplify matters by storing only three items of data:

  • The latitude and longitude of the placemark (using the Point class, which we will implement later in this article).
  • The formatted address as returned by the geocoder.
  • The accuracy of the location (that is, whether the location is a specific street address, a region, country or otherwise). The different accuracies were covered earlier in this article.

To implement this class, we will create functions to set and get each of these items. That is, we will implement setPoint(), getPoint(), setAddress(), getAddress(), setAccuracy() and getAccuracy(). We will also implement the static FromSimpleXml() method that is used by the Geocoder class.

The code for this class should reside in a file called Placemark.php. The complete file is available from the article file downloads section.

Listing 11 shows the beginning of the Placemark class, in which we define constants for the different accuracy levels. While we will not be using these values in the class, including them allows you to determine the kind of placemark. For example, to determine whether or not a placemark refers to a country, you could use if ($placemark->getAccuracy() == Placemark::ACCURACY_COUNTRY) { … } (where $placemark is an instance of Placemark).

When initializing this class we also create properties for the point, address and accuracy value. We define these as protected, allowing you to access these values using the corresponding get and set methods.

<?php

class Placemark

{

const ACCURACY_UNKNOWN     = 0;

const ACCURACY_COUNTRY     = 1;

const ACCURACY_REGION       = 2;

const ACCURACY_SUBREGION   = 3;

const ACCURACY_TOWN         = 4;

const ACCURACY_POSTCODE     = 5;

const ACCURACY_STREET      = 6;

const ACCURACY_INTERSECTION = 7;

const ACCURACY_ADDRESS     = 8;

 

protected $_point;

protected $_address;

protected $_accuracy;

 

// other code

}

?>

Note: The Google Maps API doesn’t define named constants for the different accuracy levels (unlike with the response status codes).

Next we define the methods to manage the address value. Listing 12 shows the setAddress() and getAddress() methods. Additionally, I have defined the __toString() method (which simply returns the return value from getAddress()), thereby allowing you to echo a placemark easily (that is, you can use echo $placemark;, rather than needing to use echo $placemark->getAddress();).

Also note that we cast the $address variable to a string in setAddress(). This is done because in our code it will be passed in from SimpleXML, meaning technically its type will not be a string.

<?php

class Placemark

{

// other code

 

public function setAddress($address)

{

$this->_address = (string) $address;

}

 

public function getAddress()

{

return $this->_address;

}

 

public function __toString()

{

return $this->getAddress();

}

 

// other code

}

?>

Next we implement the setPoint() and getPoint() methods, as shown in Listing 13. The setPoint() method accepts a Point object, while getPoint() returns that object. We will implement the Point class shortly.

<?php

class Placemark

{

// other code

 

public function setPoint(Point $point)

{

$this->_point = $point;

}

 

public function getPoint()

{

return $this->_point;

}

 

// other code

}

?>

We now add the setAccuracy() and getAccuracy() methods, which are used to manage the accuracy value returned from the geocoder response. These are shown in Listing 14.

<?php

class Placemark

{

// other code

 

public function setAccuracy($accuracy)

{

$this->_accuracy = (int) $accuracy;

}

 

public function getAccuracy()

{

return $this->_accuracy;

}

 

// other code

}

?>

Finally we can implement the FromSimpleXml() method, which is a static factory method that constructs an instance of Placemark based on the SimpleXMLElement object passed to it. Listing 15 shows the code for FromSimpleXml(), which begins by creating an instance of Point based on the coordinates supplied by the geocoder response.

The point, address and accuracy are then set accordingly on the newly created Placemark object, which is then returned. We will cover the creation of the Point class and its Create() method in the next section. For now, all we need to know is that Create() returns an instance of Point.

<?php

class Placemark

{

// other code

 

public static function FromSimpleXml($xml)

{

require_once(‘Point.php’);

$point = Point::Create($xml->Point->coordinates);

 

$placemark = new self;

$placemark->setPoint($point);

$placemark->setAddress($xml->address);

$placemark->setAccuracy($xml->AddressDetails[‘Accuracy’]);

 

return $placemark;

}

}

?>

This now completes the Placemark class, which can all be used as is except for the FromSimpleXml() method, which still requires the Point class.

Creating the Point Class

The final class we need to implement to make use of our geocoder is the Point class. This class is to hold a single latitude and longitude value. These values are set by passing them in the class constructor, and retrieved by calling the getLatitude() and getLongitude() methods respectively.

The other method we will implement in this class is a static factory method called Create(), which is called by the Placemark class.

The code for this class should reside in a file called Point.php. The complete file is available from the article file downloads section.

We begin the Point class in Listing 16, by creating properties for the latitude and longitude, as well as implementing the constructor, used to set these values.

<?php

class Point

{

protected $_lat;

protected $_lng;

 

public function __construct($latitude, $longitude)

{

$this->_lat = $latitude;

$this->_lng = $longitude;

}

 

// other code

}

?>

Next we implement the methods used to retrieve the longitude and latitude values, as shown in Listing 17.

<?php

class Point

{

// other code

 

public function getLatitude()

{

return $this->_lat;

}

 

public function getLongitude()

{

return $this->_lng;

}

 

// other code

}

?>

Finally, we implement the Create() factory method. This static method accepts a string in the format we receive it from the geocoder (that is, latitude,longitude,elevation). To create the new Point object we simply split this string on the comma character and instantiate Point with the values, as shown in Listing 18.

<?php

class Point

{

// other code

 

public static function Create($str)

{

list($longitude, $latitude, $elevation) = explode(‘,’, $str, 3);

 

return new self($latitude, $longitude);

}

}

?>

This concludes the three classes that make up our geocoder, meaning we now use the geocoder as required. In the next section we will implement a simple web-based interface to the geocoder.

Using the Geocoder

Now that the Geocoder, Placemark and Point class are complete, we can make use of our geocoding implementation. To do so, we will now create a simple web-based interface to the geocoder. This script will display a form with a single text input, which allows the user to enter their desired location to find coordinates for. When they submit the form, the request will be sent to Google and the results will be displayed to the user.

The code for this script can be written to any file you like, but I have called it index.php for the sake of this article. The full script is available from the article file downloads section.

This code works by displaying a form that submits back to itself. At the start of the class we check if the address value has been submitted, and if so a geocoder request is performed.

Listing 19 shows the beginning of the index.php file, which first checks the $_GET variable for a submitted address. If there is a value, the Geocoder class is instantiated and a request is performed. I have also included some basic exception handling. That is, if an error occurs (such as invalid key being specified), the code is displayed and the script exits.

<?php

if (isset($_GET[‘address’]))

$address = $_GET[‘address’];

else

$address = ”;

 

$lookupPerformed = false;

 

if (strlen($address) > 0) {

require_once(‘Geocoder.php’);

$geocoder = new Geocoder(‘your key here’);

 

try {

$placemarks = $geocoder->lookup($address);

}

catch (Exception $ex) {

echo $ex->getMessage();

exit;

}

 

$lookupPerformed = true;

}

?>

Note: Once again, remember to substitute in your own Google Maps API key. Also remember that you don’t have to hard-code this value; it may be stored in another script, an external file or in a database.

Next we include the HTML output in the index.php script, as shown in Listing 20. At the top of the page we show the form, which consists of a text input and a submit button. If a request has been submitted we re-display that value in the text input.

<html>

<head>

<title>Google Geocoder</title>

</head>

<body>

<div>

<form method=”get” action=”index.php”>

<div>

<input type=”text”

name=”address”

value=”<?php echo htmlSpecialChars($address) ?>” />

<input type=”submit” value=”Lookup” />

</div>

</form>

Note: Remember to escape the user-submitted variable $address using htmlSpecialChars() to prevent malicious code from being executed (or to prevent characters being displayed that will break the HTML output, such as “).

Next we check if a geocoder request has been performed (using the $lookupPerformed variable created in Listing 19), and if so, we output the results from the request. Listing 21 shows the code used to do this, which outputs each returned placemark with its formatted and its coordinates.

<?php if ($lookupPerformed) { ?>

<hr />

 

<h2>Geocoder Results</h2>

 

<?php if (count($placemarks) > 0) { ?>

<dl>

<?php foreach ($placemarks as $placemark) { ?>

<dt><?php echo htmlSpecialChars($placemark) ?></dt>

<dd>

Latitude <?php echo $placemark->getPoint()->getLatitude() ?>,

Longitude <?php echo $placemark->getPoint()->getLongitude() ?>

</dd>

<?php } ?>

</dl>

<?php } else { ?>

<p>

No matches found for <strong><?php echo htmlSpecialChars($address) ?></strong>

</p>

<?php } ?>

<?php } ?>

</div>

</body>

</html>

This now concludes the code required to use the geocoder. In Figure 1, I have shown the output when querying main st, usa. This is an ambiguous location that results in many matches from the geocoder.

Conclusion

In this article we have looked closely at how to use the free geocoder web service provided to users of Google Maps. While there is also a geocoder than can be used within your JavaScript code when using the Google Maps API, not all users will necessarily have JavaScript. This means that if you do choose to use the JavaScript geocoder, you should not rely on the user being able to do so.

After learning how to perform a request and to understand the results, we implement a PHP solution made up of three classes: Geocoder, Placemark and Point, which make using the Google geocoder very straightforward.

We finished the article by implementing a simple web-based interface to the geocoder, which allowed users to enter an address and retrieve the resulting locations.

While we didn’t implement a caching solution in this article, you should always try to minimize the number of geocoding requests that your application performs by saving the responses for future use. This is done not only increase performance but to also not go over the quota allocated by Google.

References

 

 

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *