Google Maps V3 Geocoding Server-Side

Google Maps v3 geocoding server-side

I am not sure if I understand you correctly but this is the way I do it (if you are interested)

void GoogleGeoCode(string address)
{
string url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=";

dynamic googleResults = new Uri(url + address).GetDynamicJsonObject();
foreach (var result in googleResults.results)
{
Console.WriteLine("[" + result.geometry.location.lat + "," + result.geometry.location.lng + "] " + result.formatted_address);
}
}

using the extension methods here & Json.Net

Google Maps API v3 geocoding web service with key to monitor usage

At this time, there's no support for api key in geocoding request and it seems intentional per api documentation. The current parameter is a legacy from V2, and in the api console there isn't an available service for geocoding api.

https://developers.google.com/maps/documentation/geocoding/?hl=en#Limits

So, stick to keyless requests, and if you want to monitor your usage, you should log yourself and watch for OVER_QUERY_LIMIT responses.

Parsing Google Maps API GeoCode - server side or client side?

Is this a website or an application that you need to hit geocoding servers on every request? If so, you should use client-side.

If you have some predefined latLng values then you can use server side geocoding and cache the results for a couple of hours. This way, you probably won't need to worry about quota.

From Google Developers' site:

When to Use Client-Side Geocoding

The basic answer is "almost always." As geocoding limits are per user
session, there is no risk that your application will reach a global
limit as your userbase grows. Client-side geocoding will not face a
quota limit unless you perform a batch of geocoding requests within a
user session. Therefore, running client-side geocoding, you generally
don't have to worry about your quota.

See here

Geocoding API key should be server-restricted

In order to make Google Maps Web Service requests from a mobile device (without using the Google Maps SDK), you have to use an unrestricted key. Each mobile device has its own IP address and it is not feasible to set IP address restrictions to all the mobile devices that use your app.

Android or iOS API key application restrictions only work for requests made through the Android or iOS SDK.

If you want to use a restricted key for web service requests from mobile devices, you have to use a proxy server that makes the requests on behalf of the mobile app.

What is the proper way of sending many requests to Google Maps Geocoding API?

Related question:

  • OVER_QUERY_LIMIT in Google Maps API v3: How do I pause/delay in Javascript to slow it down?

See:

  • Geocoding Addresses Best Practices

This section:

Managing errors and retries

If you get an OVER_QUERY_LIMIT status code as a response, you have exceeded the usage limits for the API. We recommend you try these usage optimization strategies.

  • Usage Optimization Strategies

Rate limits
The geocoding service is rate limited to 50 QPS (queries per second), calculated as the sum of client-side and server-side queries.

There is a suggestion in the documentation for the web services: Best Practices Using Google Maps APIs Web Services to use Exponential Backoff:

Exponential Backoff
In rare cases something may go wrong serving your request; you may receive a 4XX or 5XX HTTP response code, or the TCP connection may simply fail somewhere between your client and Google's server. Often it is worthwhile re-trying the request as the followup request may succeed when the original failed. However, it is important not to simply loop repeatedly making requests to Google's servers. This looping behavior can overload the network between your client and Google causing problems for many parties.

A better approach is to retry with increasing delays between attempts. Usually the delay is increased by a multiplicative factor with each attempt, an approach known as Exponential Backoff.



Related Topics



Leave a reply



Submit