I am trying to alter the events module so that you can give the event a location which will be displayed on a google map on the website.
At the moment I have added fields so you can enter longitude and latitude but what I would really like to do is add in a google map so people can drag the marker to the location they want and that will generate the longitude and latitude.
I have the googlemap code working on a test file http://bible.bpweb.net/googlemaptest.html but I cant figure out how to add it to the admin page. I am not getting any error messages just an empty space where the map should appear. At the moment I am not concerned about linking it to any of the form fields, I am just trying to get the map to appear!
I have changed the template to
Code: Select all
{$startform}
<div class="pageoverflow">
<p class="pagetext">*{$prompt_short}:</p>
<p class="pageinput">{$input_short}</p>
</div>
<div class="pageoverflow">
<p class="pagetext">Summary:</p>
<p class="pageinput">{$input_summary}</p>
</div>
<div class="pageoverflow">
<p class="pagetext">*{$prompt_long}:</p>
<p class="pageinput">{$input_long}</p>
</div>
<div class="pageoverflow">
<p class="pagetext">Location</p>
<p class="pageinput">{$input_location}</p>
</div>
<div class="pageoverflow">
{literal}
<__script__ src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjETekHX1BrskcQywhkrYOxRtiL-cSRPPhIaiZ0Cdon549B3RWxQh_7ualzt-3LPymKTLJXXMH2KP0g"
type="text/javascript"></__script>
<__script__ type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
var marker = null;
load();
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.addControl(new GOverviewMapControl());
map.setCenter(new GLatLng(55.37813515249014, -3.4352874755859375), 5);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert("Sorry, we were unable to find " + address + ".");
} else {
var lat = point.lat();
var lng = point.lng();
map.setCenter(new GLatLng(lat,lng), 13);
if (marker) map.removeOverlay(marker);
marker = new GMarker(point, {draggable: true});
//document.forms["mapForm"].elements["latitude"].value = lat;
// document.forms["mapForm"].elements["longtitude"].value = lng;
//alert("The coordinates are: " + lat + ", " + lng);
GEvent.addListener(marker, "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function() {
marker.openInfoWindowHtml("This is the new position");
var lat = marker.getPoint().lat();
var lng = marker.getPoint().lng();
//alert("The coordinates are: " + lat + ", " + lng);
// document.forms["mapForm"].elements["latitude"].value = lat;
// document.forms["mapForm"].elements["longtitude"].value = lng;
});
map.addOverlay(marker);
marker.openInfoWindowHtml("This is the location that you marked");
}
}
);
}
}
//]]>
</__script>
{/literal}
<div id="map" style="width: 550px; height: 450px"></div>
</div>
<div class="pageoverflow">
<p class="pagetext">Longitude</p>
<p class="pageinput">{$input_longitude}</p>
</div>
<div class="pageoverflow">
<p class="pagetext">Latitude</p>
<p class="pageinput">{$input_latitude}</p>
</div>
<div class="pageoverflow">
<p class="pagetext">*{$prompt_start_date}:</p>
<p class="pageinput">
Date:
{html_select_date
prefix=$prefix_startdate
time=$start_date
start_year="-5"
end_year="+10"}
Time:
{html_select_time
display_seconds=false
minute_interval=15
prefix=$prefix_startdate
time=$start_date}
</p>
</div>
<div class="pageoverflow">
<p class="pagetext">*{$prompt_end_date}:</p>
<p class="pageinput">
Date:
{html_select_date
prefix=$prefix_enddate
time=$end_date
start_year="-5"
end_year="+10"}
Time:
{html_select_time
display_seconds=false
minute_interval=15
prefix=$prefix_enddate
time=$end_date}
</p>
</div>
<div class="pageoverflow">
<p class="pagetext"> </p>
<p class="pageinput">{if isset($idfield)}{$idfield}{/if}{$submit}{$cancel}{$apply}</p>
</div>
{$endform}
Thank you
Rachael