Skip to content

Instantly share code, notes, and snippets.

@katzueno katzueno/controller.php

Last active Jun 20, 2018
Embed
What would you like to do?

concrete5.6.x Google Map Block fix to enter API key

  1. Obtain the file below
  2. Add your Google Map API key to line 8.
  3. Upload this file under blocks/google_map/controller.php
  4. Done

concrete5.6.x で Google Map ブロックに API キーを入れるハック

  1. 下記のファイルを取得
  2. 8行目あたりの XXXXXXX と書いてあるところに、Google Map Key を入力
  3. このファイルを blocks/google_map/controller.php にアップロード
  4. 以上

Updated on June 20, 2018

<?php
defined('C5_EXECUTE') or die("Access Denied.");
class GoogleMapBlockController extends Concrete5_Controller_Block_GoogleMap
{
public function on_page_view() {
// Insert Google Map API Key here
// ここに Google Map API Key を入れてください
$apikey = 'XXXXXXXXXXX';
$balloonHtml = '';
if($this->balloonShow) {
$balloonHtml = '<div style="overflow:hidden;white-space:nowrap;">';
if(strlen($this->balloonContent)) {
$balloonHtml .= Loader::helper('content')->translateFrom($this->balloonContent);
}
if($this->balloonWithLinkToMaps) {
$balloonHtml .= '<div style="font-size: smaller"><a href="//maps.google.com?' . h('ll=' . $this->latitude . ',' . $this->longitude . '&daddr=' . $this->latitude . ',' . $this->longitude . '&z=' . $this->zoom) . '" target="blank">' . h(t('Get Directions')) . '</a>&nbsp;&nbsp;</div>';
}
$balloonHtml .= '</div>';
$this->set('balloonHtml', $balloonHtml);
}
$html = Loader::helper('html');
$c = Page::getCurrentPage();
if (!$c->isEditMode()) {
$this->addFooterItem('<script type="text/javascript" src="//maps.google.com/maps/api/js?key=' . $apikey . '&sensor=true&language=' . rawurlencode(str_replace('_', '-', Localization::activeLocale())) . '"></script>');
$this->addFooterItem('<script type="text/javascript">
function googleMapInit' . $this->bID . '() {
try{
var latlng = new google.maps.LatLng(' . $this->latitude . ', ' . $this->longitude . '), balloonHtml = ' . Loader::helper('json')->encode($balloonHtml) . ', balloon;
var mapOptions = {
zoom: ' . $this->zoom . ',
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false,
mapTypeControl: false
};
var map = new google.maps.Map(document.getElementById(\'googleMapCanvas' . $this->bID . '\'), mapOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
if(balloonHtml) {
balloon = new google.maps.InfoWindow({content: balloonHtml});
google.maps.event.addListener(marker, "click", function() {
balloon.open(map, marker);
});
setTimeout(function() {
balloon.open(map, marker);
}, 500);
}
}catch(e){
$("#googleMapCanvas'. $this->bID .'").replaceWith("<p>Unable to display map: "+e.message+"</p>")}
}
$(function() {
var t;
var startWhenVisible = function (){
if ($("#googleMapCanvas'. $this->bID .'").is(":visible")){
window.clearInterval(t);
googleMapInit' . $this->bID . '();
return true;
}
return false;
};
if (!startWhenVisible()){
t = window.setInterval(function(){startWhenVisible();},100);
}
});
</script>');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.