Skip to content

Commit

Permalink
* Update Google static map to use optional scale, as well as make hei…
Browse files Browse the repository at this point in the history
…ght and width optional.

* Added Google API key to static map
* Removed depreciated sensor parameter
  • Loading branch information
Mark Taylor committed Sep 22, 2017
1 parent 60af1b3 commit 7eb2f81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions code/Addressable.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,18 @@ public function getFullAddressHTML() {
/**
* Returns a static google map of the address, linking out to the address.
*
* @param int $width
* @param int $height
* @param int $width (optional)
* @param int $height (optional)
* @param int $scale (optional)
* @return string
*/
public function AddressMap($width, $height) {
public function AddressMap($width = 320, $height = 240, $scale = 1) {
$data = $this->owner->customise(array(
'Width' => $width,
'Height' => $height,
'Address' => rawurlencode($this->getFullAddress())
'Scale' => $scale,
'Address' => rawurlencode($this->getFullAddress()),
'Key' => Config::inst()->get('GoogleGeocoding', 'google_api_key')
));
return $data->renderWith('AddressMap');
}
Expand Down
4 changes: 2 additions & 2 deletions templates/AddressMap.ss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="addressMap">
<a href="//maps.google.com/?q=$Address">
<img src="//maps.googleapis.com/maps/api/staticmap?size={$Width}x{$Height}&markers=$Address&sensor=false" alt="$FullAddress.ATT" />
<img src="//maps.googleapis.com/maps/api/staticmap?size={$Width}x{$Height}&scale={$Scale}&maptype={$MapType}&markers=$Address&key=$Key" alt="$FullAddress.ATT" />
</a>
</div>
</div>

0 comments on commit 7eb2f81

Please sign in to comment.