The function function geocode($input, $options) as an $options param but it's not used in the fuction. The $input pass trought urlencode so you can't pass extra params tought this one. Now if you see the http://code.google.com/intl/fr/apis/maps/documentation/geocoding/ sensors and key is requiered so i think we can use $options for this like that:

        require_once(drupal_get_path('module','geocode').'/includes/geocode.inc');
        $geocode = new geocode_google();
        $options = '&key=' . variable_get('googlemap_api_key', ''); //take the gmap key
        $options .=  '&sensor=false';
        $googleQuery = $assigned['city'].'+Switzerland';
        $ret = $geocode->geocode($googleQuery,$options);

In the file geocode.inc

  function geocode($input, $options) {
    if (is_array($input)) $input = join(',', $input);
    $url = "http://maps.google.com/maps/geo?";
    $url .= 'q='. urlencode($input);
    $url .= $options;
    $url .= '&output=json&oe=utf-8';
    $ret = drupal_http_request($url);
CommentFileSizeAuthor
#1 606380-geocode-options.patch1.59 KBmr.baileys

Comments

mr.baileys’s picture

Status: Active » Needs review
StatusFileSize
new1.59 KB

Agreed - I'm trying out Geocode for a project of mine, but in order to be useful I need to be able to pass options:

  • bounds: our application is very local, and being able to restrict address searches to just a couple of cities via Google's 'bounds' option is incredibly useful
  • key: We are not using the GMAP module. While we can set the googlemap_api_key value, having the option to pass in the key as an argument seems more flexible and less of a hack.

I've rolled a patch that refactors the geocode call as follows:

  • Set up a set of default options for each google geocode call, including the gmap key and sensor values
  • Merge the passed in $options array with the default options, overriding the default options when present in the $options array
  • Replaced the string concatenation and url encoding with a call to url, as that function takes care of building the full url and appending/encoding the query parameters.

Current invocations of geocode() will continue to work, but after applying this patch you can use the follow calls:

geocode('700 12st Washington DC', array('key' => 'ABCDEF...', 'language' => 'nl', 'bounds' => '38.598899,-76.728236|39.298899,-77.328236'))
Searches for the address within the bounding box, using GMAP key 'ABCDEF...' and returning the results in Dutch.
geocode('700 12st Washington DC', array('sensor' => 'true')
Tells google that the request comes from a device with a location sensor.