Jump to:

10930 Posts in 2613 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Googlemaps

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1111 Views
  • mhull
    Avatar
    Community Member
    79 Posts

    Googlemaps Link to this post

    Not Strictly a module, but a template that was written a while back and I had working in the last version of silverstripe, is now not working in 2.3. Can anyone shed any light?

    class GMapPage extends Page {
    static $db = array (
    'GoogleMapsScriptURL' => 'Text',
    'GoogleMapsAPIKey' => 'Text',
    'MapControl' => 'Boolean',
    'MapControlSize' => 'VarChar',
    'MapTypeControl' => 'Boolean',
    'MapSearchControl' => 'Boolean',
    'MapMarker' => 'Boolean',
    'MapMarkerInfo' => 'Boolean',
    'Latitude' => 'Text',
    'Longitude' => 'Text',
    'Zoom' => 'Int',
    'AddressLine1' => 'Text',
    'AddressLine2' => 'Text',
    'AddressLine3' => 'Text',
    'PostCode' => 'Text',
    );

    static $allowed_children = "none";

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.MapConfig', new TextField('GoogleMapsScriptURL'),'Content');
    $fields->addFieldToTab('Root.Content.MapConfig', new TextField('GoogleMapsAPIKey'),'Content');
    $fields->addFieldToTab(
    'Root.Content.MapOptions',
    new FieldGroup(
    new CheckboxField("MapControl", "Add a Map Control"),
    new OptionsetField(
    "MapControlSize",
    " - Choose type",
    array(
    "Small" => "Small",
    "Large" => "Large",
    )
    )
    ),
    'Content'
    );
    $fields->addFieldToTab(
    'Root.Content.MapOptions',
    new FieldGroup(
    new CheckboxField("MapTypeControl", "Add a Map Type Control"),
    new CheckboxField("MapSearchControl", "Add a Map Search Control"),
    new CheckboxField("MapMarker", "Add a Map Marker"),
    new CheckboxField("MapMarkerInfo", "Add an Info Window to the Marker")
    ),
    'Content'
    );
    $fields->addFieldToTab('Root.Content.MapOptions', new FieldGroup(new NumericField("Zoom", "Enter map zoom value, 1-15", "13")),'Content');
    $fields->addFieldToTab(
    'Root.Content.MapOptions',
    new FieldGroup(
    new HeaderField('Co-ordinates',2),
    new LiteralField('Blank','<p></h3>Leave blank to use Address</h3></p>'),
    new TextField('Latitude','Latitude'),
    new TextField('Longitude','Longitude')
    ),
    'Content'
    );
    $fields->addFieldToTab("Root.Content.Address", new TextField('AddressLine1'),'Content');
    $fields->addFieldToTab("Root.Content.Address", new TextField('AddressLine2'),'Content');
    $fields->addFieldToTab("Root.Content.Address", new TextField('AddressLine3'),'Content');
    $fields->addFieldToTab("Root.Content.Address", new TextField('PostCode'),'Content');

    return $fields;
    }

    }

    class GMapPage_Controller extends Page_Controller {
    function GetGoogleMapsScript() {
    $gmap = DataObject::get_one('GMapPage');

    Requirements::javascript($gmap->GoogleMapsScriptURL.$gmap->GoogleMapsAPIKey);
    Requirements::javascript("http://www.google.com/uds/api?file=uds.js&amp;v=1.0");
    Requirements::javascript("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js");
    Requirements::insertHeadTags(
    "<style type='text/css'>
    @import url(http://www.google.com/uds/css/gsearch.css);
    @import url(http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css);
    </style>"
    );

    $this->address = $gmap->AddressLine1 . ", " . $gmap->AddressLine2;
    $gmap->infoWindow = "'" . $this->address . "'";
    (is_Null($gmap->Latitude) OR is_Null($gmap->Longitude)) ? ($gmap->Latitude = $gmap->Longitude = "null") : ($gmap->Latitude);
    $gmap->MapControlSize = "G" . $gmap->MapControlSize . "MapControl()";

    $code .= <<<ScriptCode
    <script type="text/javascript">
    //<![CDATA[
    var map = null;
    var geocoder = null;
    var checkLatLng = $gmap->Latitude;
    var MapControl = $gmap->MapControl;
    var MapTypeControl = $gmap->MapTypeControl;
    var MapSearchControl = $gmap->MapSearchControl;
    var MapMarker = $gmap->MapMarker;
    var MapMarkerInfo = $gmap->MapMarkerInfo;

    function load() {
    if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("Map"));
    if (null==checkLatLng) {
    geocoder = new GClientGeocoder();
    showAddress("$this->address");
    }
    else {
    var latlng = new GLatLng($gmap->Latitude, $gmap->Longitude);
    map.setCenter(latlng, $gmap->Zoom);
    }
    if (MapControl == "1") {map.addControl(new $gmap->MapControlSize);}
    if (MapTypeControl == "1") {map.addControl(new GMapTypeControl());}
    if (MapSearchControl == "1") {
    // bind a search control to the map, suppress result list
    map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
    }

    }
    else {
    alert("Your browser is not compatible with the mapping tool.");
    }
    }
    GSearch.setOnLoadCallback(load);

    function showAddress(address) {
    if (geocoder) {
    geocoder.getLatLng(
    address,
    function(point) {
    if (!point) {
    alert(address + " not found");
    } else {
    map.setCenter(point, $gmap->Zoom);
    if (MapMarker == "1") {
    var marker = new GMarker(point);
    map.addOverlay(marker);
    }
    if (MapMarkerInfo == "1") {
    marker.openInfoWindowHtml($gmap->infoWindow);
    GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml($gmap->infoWindow);});
    }
    }
    }
    );
    }
    }
    //]]>
    </script>
    ScriptCode;

    return $code;
    }
    }
    ?>

    The error is showing Undefined variable: code and highlighting line 155: ScriptCode;

    Any help would be much appreciated

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: Googlemaps Link to this post

    Can anyone offer any suggestions with why this isn't working in 2.3?

    1111 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.