Skip to content

Instantly share code, notes, and snippets.

@stborchert
Last active December 15, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stborchert/5221629 to your computer and use it in GitHub Desktop.
Save stborchert/5221629 to your computer and use it in GitHub Desktop.
<?php
/**
* Generate a simple map with a location pointer.
*
* @param string $location
* Location to use (for example the address).
* @param string $country
* Name of the country to use.
*
* @return string
* The rendered map.
*/
function mysimplemap_map_create($location, $country) {
$map = '';
// Join the address parts to something geocoder / google maps understands.
$address = sprintf('%s, %s', $location, $country);
// Try to create a geographic point out of the given location values.
if ($geo_point = geocoder('google', $address)) {
// Create a JSON equivalent to the point.
$geo_json = $geo_point->out('json');
// Get map implementation provided by http://drupal.org/project/leaflet_googlemaps.
$map = leaflet_map_get_info('google-maps-roadmap');
// Set initial zoom level.
$map['settings']['zoom'] = 16;
// Decode the JSON string.
$geo_data = json_decode($geo_json);
// Create settings for the map.
$map_features = array(
array(
'type' => 'point',
'lon' => $geo_data->coordinates[0],
'lat' => $geo_data->coordinates[1],
),
);
// Render the map with a fixed height of 250 pixels.
$map = leaflet_render_map($map, $features, '250px');
}
return $map;
}
?>
@mxr576
Copy link

mxr576 commented Oct 20, 2015

There is typo in your code I think in the 38th line. The $features should be $map_features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment