Wiki source for GoogleMap


Show raw source

=====Google Map=====

>>**Try the demo:**
~[[http://nitens.org/taraborelli/map | Wikka Developers Location]]
>>The [[http://www.google.com/apis/maps/ | Google Maps API]] lets developers embed Google Maps in their own web pages with JavaScript. You can add overlays to the map (including markers and polylines) and display shadowed "info windows" just like [[http://maps.google.com/ | Google Maps]]. //(quoted from [[http://www.google.com/apis/maps/ | Google maps API homepage]]).//
::c::
Based on [[PivWan]]s idea to use this service to build a UserMap, here is the first code for a googlemap action.

~& Enhanced to use various parameters and api v2 (Experimented on http://wikka.pnconcept.com/GoogleMap)
~~& Thank you Frank! I added you to the authors in the action-file.

add the following as ##actions/googlemap.php##

%%(php;1)
<?php
/**
* Prints a map from Googles Map-service on a page.
*
* Note that you have to register your (sub)domain with google to get a key to use the map.
* See http://www.google.com/apis/maps/signup.html for details.
*
* @package actions
* @author {@link http://www.wikkawiki.org/NilsLindenberg Nils Lindenberg} (initial version)
* @author {@link http://www.wikkawiki.org/SamuelDR SamuelDR} (bugfix)
* @author {@link http://www.wikkawiki.org/FrankChestnut FrankChestnut} (various parameters and api v2)
*
* @todo: - Load markers from...
* - phpdoc document params
*/

//the key you get from google
$key = 'ABC';

// defaults
$latitude = '37.441944';
$longitude = '-122.141944';
$width = '300';
$height = '300';
$maptype = 'G_NORMAL_MAP';
$zoom = '4';
$overview = false;

$maptypes = array('normal' => 'G_NORMAL_MAP',
'satellite' => 'G_SATELLITE_MAP',
'hybrid' => 'G_HYBRID_MAP');

// E_ALL fix
if (isset($vars) && is_array($vars)) {
if (isset($vars['latitude']) && !empty($vars['latitude'])) {
$latitude = $vars['latitude'];
}
if (isset($vars['longitude']) && !empty($vars['longitude'])) {
$longitude = $vars['longitude'];
}
if (isset($vars['width']) && !empty($vars['width'])) {
$width = $vars['width'];
}
if (isset($vars['height']) && !empty($vars['height'])) {
$height = $vars['height'];
}
if (isset($vars['zoom']) && !empty($vars['zoom'])) {
$zoom = $vars['zoom'];
}
if (isset($vars['maptype']) && array_key_exists($vars['maptype'], $maptypes)) {
$maptype = $maptypes[$vars['maptype']];
}
if (isset($vars['overview']) && !empty($vars['overview'])) {
// 0 & '0' are considered empty so there is no need for further checks
$overview = true;
}
}

?>

<script src="http://maps.google.com/maps?file=api&v=2&key=<?php echo $key ?>" type="text/javascript"></script>
<div id="map" style="width: <?php echo $width ?>px; height: <?php echo $height ?>px"></div>
<script type="text/javascript">
//<![CDATA[
setTimeout("ShowGoogleMap()", 100);

function ShowGoogleMap()
{

if (GBrowserIsCompatible()) {

var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
<?php
if ($overview) {
?>
map.addControl(new GOverviewMapControl());
<?php
}
?>

map.setCenter(new GLatLng(<?php echo $latitude ?>, <?php echo $longitude ?>, <?php echo $zoom ?>), <?php echo $zoom ?>);
map.setMapType(<?php echo $maptype ?>);
}
}

//]]>
</script>
%%

This will print out a map with 300 x 300 pixel and the controls to change between map/satellite-picture and To move/zoom-in zoom-out. The map is centered to Paolo Alto.

====Available parameters====


- **latitude**
- **logitude**
- **width**
- **height**
- **maptype** (normal, satellite, hybrid)
- **zoom**
- **overview** ("0"/"1") (Show minimap - default: "0")


====Todo====
- params for width/height, controlls, location and other possible additions to a map, see the [[http://www.google.com/apis/maps/documentation/ | documentation]]. **Done**
- Load markers from...........

====Discussion====
~& From: FrankChestNut --- --- Little follow up about a google map... --- Here is a little concept : http://www.ubuntu-fr.org/map/ (Beware... ridiculously long to load) --- From what I understand from the source, people add their coordinates on this page http://doc.ubuntu-fr.org//utilisateurs/ou_sommes_nous --- And an admin probably do a copy/paste of the markers section into a data.xml file http://www.ubuntu-fr.org/map/data.xml --- On one side, not too bad, on the other, kind of a poor way to do the thing. But the basic idea is there. A way could be found to generate dynamically a xml output (like RecentChanges) and use it to compile the markers to put on the map. --- Regards! --- F.C. !
~~& From: DarTar --- --- Hi Frank, --- what I had in mind was actually something quite similar to the Ubuntu thing (which is so heavy that it crashes my browser!). The way I see it, there are three possible ways of implementing GM functionality within Wikka:
~~~1) As an action: --- ##""{{googlemap source="blablabla.xml"}}""## --- Actions are used to generate content within a page, so this might be the most natural way to implement this kind of functionality. The problem with this approach is that the XML data source should be created manually, as you suggest, and this is not an interesting option. Alternatively we could have data stored as plain text in another page (say ""MyPage"") and use a specific '/xml' handler to parse this page and generate the data file to be used by the action, e.g. --- ##""{{googlemap source="MyPage/xml"}}""##
~~~2) As a handler: --- http://wikkawiki.org/HomePage/googlemap --- A handler typically performs operations on a page as a whole. A ##/googlemaps## handler could display a specific map depending on whether specific strings are present in the page body or, alternatively - if appended to a UserPage - display the location of the user (as stored in a dedicated field of the user table).
~~~3) As a formatter --- Maybe the most interesting way to implement Google Maps would be to use a specific markup, e.g.
~~&%%
::(gm)
center: 45,76878;2,56658;
type: satellite;
zoom: 7;
width: 250px;
marker: 1; 45,76878; 2,666; DarTar;
marker: 2; 46,54763; 3,666; WikkaWiki;
::
%%
~~& (note this is just a mockup of possible markup, to give an idea of what I have in mind) --- This would allow users to easily generate google maps with markers within a wiki, without the need of bothering with XML. The major drawback with this approach is that - because of the way in which the Wikka formatter is built- it's very difficult to introduce a "modular" formatter, so this should be core functionality - which definitely goes against Wikka's vision. Maybe GM support could be the occasion for an overhaul of the functioning of Wikka formatters? --- --DarTar
~~~& From: FrankChestnut --- --- From what I saw on the last ##formatter/wakka.php##, you are not necessarily that far from modularity. Not that what is there is necessarily the solution but... --- What I mean is the part where you define de ##PATTERN_XXX constants##... (wasn't in 1.1.6.0 iirc) --- All the regex could be either constants (or coming from another source) instead of being hardcoded. --- If you define a way for people to have a custom markup definition file, people could use different markup. One could want to use a Doku style markup, or a PEAR style, etc. --- One example of a problem I had when porting Wikka to PostNuke was that I had a glitch with WikiEdit. I update the WikiEdit to the latest version (3.01) and found out that the list button gave a different result (2spaces*1space instead of a tab). I had to change the markup for the lists in pnWikka to reflect this change and be able to use Wikiedit whatever version it was. --- Based on what we do on PostNuke and templates, modules have their own templates. But a user can overide a specific module template (or style) by putting a different one in its theme template folder. --- The PostNuke engine will check the availability of a template in the following order : --- ##root/themes/USERTHEME/templates/modules/pnWikka/pnwikka_user_show.tpl## --- if not found, take the one that comes with the module. --- ##root/modules/pnWikka/pntemplates/pnwikka_user_show.tpl## --- The same happens for module stylesheets. --- Imagine something like this --- ##wikkaroot/user/formatters/wakka.php## --- ##wikkaroot/formatters/wakka.php## --- if file exists in ##user/formatters/##... then take this one. --- ##else##... take generic. --- You win some modularity. ;) --- And you give the power to your users to modify its markup without touching the original (most appreciated for updates). One drawback will be if you add markups. The natural extension of the solution would be of course to use different files for each tags. --- ##wikkaroot/formatters/wakka.lists.php## --- ##wikkaroot/formatters/wakka.bold.php## --- etc... --- ... but might be kind of bad on the inclusions though. --- Anyway....... writing brainstorming writing... and my coffee is getting cold. :) --- Regards... --- FC !




----
CategoryDevelopmentActions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki