Go Back   Mosets Community > Mosets Announcements and Discussions > Mosets & Joomla

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-29-2006, 09:54 AM
billguy billguy is offline
Junior Member
 
Join Date: Jul 2006
Posts: 4
Default How to embed Google maps within Mosets Tree listings

1. Sign up for a Google Maps API key, if you don’t already have one. http://www.google.com/apis/maps/signup.htm

2. Edit the sub_listingDetails.tpl.php file you are using around line 102 and add the following (Don’t forget to add your Google Maps API key):

Code:
<?php
	$key = "YourGoogleKeyGoesHere";

	$me = ($this->link->title);
	$myaddress = ($this->link->address);
	$mycity = ($this->link->city);
	$mystate = ($this->link->state);
	$myzip = ($this->link->postcode);

	$address= urlencode("$myaddress,$mycity,$mystate,$myzip");
	$lines = file ('http://maps.google.com/maps/geo?key='.$key.'&q='.$address.'&output=xml');// necessite AllowURLOpen ON
	$lines=implode( " ",$lines);
	if (ereg (".*<coordinates>([-]?[0-9\.]{7,11}),[-]?([0-9\.]{7,11}).*", $lines, $regs))
		{
  		$lat=$regs[2];
  		$long= $regs[1];
		//echo "lat: $lat  long: $long"; //format: <coordinates>2.395988,48.819813,0</coordinates>
		} 
	else 
		{
  	 	echo "Invalid Lat/Long Format";
		}

	/* Create link to Google Maps to allow users to get driving directions */
	//$GoogleBase="http://maps.google.com/maps?q=";
	//$Search = $GoogleBase.urlencode($address);
	
	/* Assemble code to generate map via the Google Maps API */
	//$content = '<h3><a href="'.$Search.'" target=_blank>'._PAGESETTER_CLICK_GOOGLE.'</a></h3><br />';

	$content = '<BR><BR><script src="http://maps.google.com/maps?file=api&v=1&key='.$key.'" type="text/javascript"></script> ';
	$content = $content.'<div id="map" style="width: 500px; height: 400px"></div> ';
  	$content = $content.'<script type="text/javascript"> ';
  	$content = $content.'setTimeout("ShowGoogleMap()", 100);';
  	$content = $content.'window.unonload = "GUnload()";';
	$content = $content.'function createMarker(point, number){ var marker = new GMarker(point);var html = "<b>" + number + "</b>";GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(html); }); return marker;}';
	$content = $content.'function ShowGoogleMap(){';
  	$content = $content.'var map = new GMap(document.getElementById("map")); ';
 	$content = $content.'map.addControl(new GSmallMapControl()); ';
  	$content = $content.'map.addControl(new GMapTypeControl()); ';
  	$content = $content.'var point = new GPoint('.$long.', '.$lat.');';
  	$content = $content.'map.centerAndZoom(point, 4);';
	$content = $content.'var marker = createMarker(point,"'.$me.'");';
  	$content = $content.'map.addOverlay(marker);';
  	$content = $content.'}';
  	$content = $content.'</script>';
	echo $content;	 
?>
3. Feel free to embellish. Don’t forget to share.


Credits: unnilennium
http://pagesetter.net/index.php?modu...b&tid=4&pid=83

Edited on 29 July 2006 by Billguy
Edited on 9 August 2006 by Billguy (-5 spelling)

Last edited by billguy; 08-10-2006 at 01:34 AM.
Reply With Quote
  #2  
Old 08-09-2006, 05:51 AM
north north is offline
Junior Member
 
Join Date: Aug 2006
Posts: 9
Default

This would be amazing Bill... problem is I don't have the file titled "sub_listingsDetails.tpl.php" in my Moset Tree directory?!

Where is this file?
Reply With Quote
  #3  
Old 08-09-2006, 09:29 PM
iidx036 iidx036 is offline
Junior Member
 
Join Date: Apr 2006
Posts: 26
Default

North - You can find that file under the: components / com_mtree / templates / bluetree_business /

Just pick the template directory you are using for mtree and it will be there.

Billguy - Just to let you know you have a typo here:

$lines = file ('http://maps.google.com/maps/geo?key='.$key.'&q='.$adress.'&output=xml');// necessite AllowURLOpen ON

Also this doesn't seem to work for UK addresses due to the geocoding issues we have in this country. The geo returns a 603 this means according to google docs that "The geocode for the given address cannot be returned due to legal or contractual reasons." I suspect this is due to the postcodes being owned by the Royal Mail and Ordnance Survey they are protected by Crown Copyright and huge fees are required to use them.

I suspect you can still do a simple search with this code but not geocode in the UK i.e. get an exact result. If anyone knows different then please let me know.

Cheers

JK

Last edited by iidx036; 08-09-2006 at 10:09 PM.
Reply With Quote
  #4  
Old 08-10-2006, 01:35 AM
billguy billguy is offline
Junior Member
 
Join Date: Jul 2006
Posts: 4
Default

Quote:
Originally Posted by iidx036
Billguy - Just to let you know you have a typo here...
Thanks.

As far as UK addresses go, you could use NuSOAP and http://www.nearby.org.uk/api/convert-help.php
to get you close. Shouldn't be too hard.

Last edited by billguy; 08-10-2006 at 02:05 AM.
Reply With Quote
  #5  
Old 08-10-2006, 09:23 PM
firstcom firstcom is offline
Junior Member
 
Join Date: Jul 2006
Posts: 11
Default

i cant get it to work in norway. I just get invalid LAT ? Anybody got this to work in norway or anywhere for that matter!
Reply With Quote
  #6  
Old 08-10-2006, 10:30 PM
billguy billguy is offline
Junior Member
 
Join Date: Jul 2006
Posts: 4
Default

Quote:
Originally Posted by firstcom
i cant get it to work in norway. I just get invalid LAT ? Anybody got this to work in norway or anywhere for that matter!
I couldnít get http://maps.google.com to work for a Norway address. I tried plugging in a couple different addresses to no avail until I found this:
http://maps.google.com/support/bin/a...y?answer=16634

I could search a city in Norway with success but not an exact address.

You might be able to geocode the city to get you close.
Reply With Quote
  #7  
Old 08-17-2006, 04:29 AM
billguy billguy is offline
Junior Member
 
Join Date: Jul 2006
Posts: 4
Default Yahoo! Traffic/Google Map Mashup

Hereís my first attempt at a Yahoo! Traffic/Google Maps mashup. Traffic data isnít available in all cities so donít be surprised if nothing shows on your map. I got the itch to do this after seeing http://traffic.poly9.com. I tested this with Beverly Hills, CA so if you live around there and use MT then youíre in luck.

You will need lastRSS.php, freely available from http://lastrss.webdot.cz. Drop that somewhere in your path (edit script to suite).

Youíll also need webticker_lib.js available from http://www.mioplanet.com/rsc/newsticker_javascript.htm. The author asks to include a link to their web site in lieu of a small fee. Of course, you can come up with something yourself if you so choose. I used the ticker to display xml weather news feeds from Yahoo! Below the map.

You can really go crazy customizing this mashup with custom icons, etc. if you choose.

Without further adieu, hereís the script (installation is similar to original post above). Enjoy!

Code:
<?php
	include 'lastrss.php';
	$rss = new lastRSS; 
	$rss->cache_dir = './././cache'; 
	$rss->cache_time = 3600; // one hour
	$key = "your_google_key_goes_here";

	$me = ($this->link->title);
	$myaddress = ($this->link->address);
	$mycity = ($this->link->city);
	$mystate = ($this->link->state);
	$myzip = ($this->link->postcode);
	$useweather = "1"; //0 to disable, 1 to enable Weather marquee
	$usetraffic = "1"; //0 to disable, 1 to enable Traffic mashup
	$adress= urlencode("$myaddress,$mycity,$mystate,$myzip");
	$lines = file ('http://maps.google.com/maps/geo?key='.$key.'&q='.$adress.'&output=xml');// necessite AllowURLOpen ON
	$lines=implode( " ",$lines);
	if (ereg (".*<coordinates>([-]?[0-9\.]{7,11}),([-]?[0-9\.]{7,11}).*", $lines, $regs))
		{
  		$lat=$regs[2];
  		$long= $regs[1];
		//echo "lat: $lat  long: $long"; //format: <coordinates>2.395988,48.819813,0</coordinates>
		} 
	else 
		{
  	 	echo "Invalid Lat/Long Format lat: $lat  long: $long";
		}

	/* Create link to Google Maps to allow users to get driving directions */
	//$GoogleBase="http://maps.google.com/maps?q=";
	//$Search = $GoogleBase.urlencode($address);
	
	/* Assemble code to generate map via the Google Maps API */
	//$content = '<h3><a href="'.$Search.'" target=_blank>'._PAGESETTER_CLICK_GOOGLE.'</a></h3><br />';
	$content = '<BR><BR><script src="http://maps.google.com/maps?file=api&v=2&key='.$key.'" type="text/javascript"></script> ';
	$content = $content.'<div id="map" style="width: 600px; height: 300px"></div> ';
  	$content = $content.'<script type="text/javascript"> ';
	$content = $content.'var icon = new GIcon();icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";icon.iconSize = new GSize(12, 20);icon.shadowSize = new GSize(22, 20);icon.iconAnchor = new GPoint(6, 20);icon.infoWindowAnchor = new GPoint(5, 1); ';
  	$content = $content.'setTimeout("ShowGoogleMap()", 100);';
  	$content = $content.'window.unonload = "GUnload()";';
	$content = $content.'var infoTabs = [' ;
	$content = $content.'new GInfoWindowTab("About", "'.$me.'<BR \>'.$myaddress.'<BR \>'.$mycity.', '.$mystate.' '.$myzip.'"),' ;
	$content = $content.'new GInfoWindowTab("Directions", "<div><form action=\"http://maps.google.com/maps\" method=\"get\"><p><label for=\"saddr\">From</label><input type=\"text\" name=\"saddr\" id=\"saddr\" value=\"\" /><p><label for=\"daddr\">To</label><input type=\"text\" name=\"daddr\" id=\"daddr\" value=\"'.$myaddress.' '.$mycity.', '.$mystate.' '.$myzip.'\" /><input type=\"submit\" value=\"Go\" /></p></form></div>")' ;
	$content = $content.'];' ;	
	$content = $content.'function createMarker(point, number){ var marker = new GMarker(point);GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowTabsHtml(infoTabs); }); return marker;}';
	$content = $content.'function createsmMarker(point, number){ var marker = new GMarker(point,icon);var html = "<b>" + number + "</b>";GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(html); }); return marker;}';
	$content = $content.'function ShowGoogleMap(){';
  	$content = $content.'var map = new GMap(document.getElementById("map")); ';
 	$content = $content.'map.addControl(new GSmallMapControl()); ';
  	$content = $content.'map.addControl(new GMapTypeControl()); ';
  	$content = $content.'map.addControl(new GScaleControl()); ';
  	$content = $content.'var point = new GPoint('.$long.', '.$lat.');';
 	$content = $content.'map.centerAndZoom(point, 4);';
	$content = $content.'var marker = createMarker(point);';
  	$content = $content.'map.addOverlay(marker);';
	$content = $content.'marker.openInfoWindowTabsHtml(infoTabs);';
       $content = $content.'map.addControl(new GOverviewMapControl()); ';

//
//This gets traffic from Yahoo!
//
if ($usetraffic == 1) {
if ($rs = $rss->get('http://api.local.yahoo.com/MapsService/rss/trafficData.xml?appid=YahooDemo&city='.$mycity.'&state='.$mystate.'')) {
   foreach($rs['items'] as $item) {
$content = $content.'var point = new GPoint('.($item['geo:long']).', '.($item['geo:lat']).');';
$content = $content.'var marker = createsmMarker(point,"'.($item['title']).'");';
$content = $content.'map.addOverlay(marker);';
	}
  }
}
  	$content = $content.'}';
  	$content = $content.'</script>';

//
//This gets the weather from Yahoo!
//
if ($useweather == 1) {
if ($weather = $rss->get('http://xml.weather.yahoo.com/forecastrss?p='.$myzip.'')) {
$content = $content.'<DIV ID="TICKER" STYLE="overflow:hidden; width:600px"onmouseover="TICKER_PAUSED=true" onmouseout="TICKER_PAUSED=false">';
    foreach($weather['items'] as $item) {
$content = $content.'<a target="new" href="'.$item[link].'">"'.$item['title'].''.$item['description'].'</a>"'; 
       }
$content = $content.'</DIV><script src="webticker_lib.js"></script>';
    } 
}
	echo $content;
?>
Reply With Quote
  #8  
Old 11-01-2006, 06:45 AM
Dionysus Dionysus is offline
Mosets'd
 
Join Date: Jul 2006
Posts: 14
Default Can you do this with Googlemaps API

How can you get moset directory to show a map like this.

http://www.atlspecials.com/index.php...e=Globe&open=1

I want to create a map with differnent icons for different types of business.

Dining, Shopping, Banking etc
Reply With Quote
  #9  
Old 09-11-2007, 11:54 AM
columbusgeek columbusgeek is offline
Member
 
Join Date: Sep 2007
Location: Ohio
Posts: 51
Default Mtree 2.0

This method still works in Mtree 2.0.xx with a bit of fiddling.

I ended up putting the code at line 171 just after

Code:
</div>
<span class="componentheading">
Props for the initial code.
I changed the default view by adding this code.

Code:
$content = $content.'map.setMapType(G_HYBRID_MAP);';
I made a separate forum thread about it here.

Last edited by columbusgeek; 10-09-2007 at 10:26 AM.
Reply With Quote
  #10  
Old 09-18-2007, 02:36 AM
Colonel P Colonel P is offline
Junior Member
 
Join Date: Sep 2007
Posts: 12
Default Google maps

Marked in red.

Change api&v=1 to api&v=2.

For the dutch guys, change maps.google.com to maps.google.nl ( 2 times).
I think this will work for most of the europian countries.

<?php
$key = "YourGoogleKeyGoesHere";

$me = ($this->link->title);
$myaddress = ($this->link->address);
$mycity = ($this->link->city);
$mystate = ($this->link->state);
$myzip = ($this->link->postcode);

$address= urlencode("$myaddress,$mycity,$mystate,$myzip");
$lines = file ('http://maps.google.com/maps/geo?key='.$key.'&q='.$address.'&output=xml');// necessite AllowURLOpen ON
$lines=implode( " ",$lines);
if (ereg (".*<coordinates>([-]?[0-9\.]{7,11}),[-]?([0-9\.]{7,11}).*", $lines, $regs))
{
$lat=$regs[2];
$long= $regs[1];
//echo "lat: $lat long: $long"; //format: <coordinates>2.395988,48.819813,0</coordinates>
}
else
{
echo "Invalid Lat/Long Format";
}

/* Create link to Google Maps to allow users to get driving directions */
//$GoogleBase="http://maps.google.com/maps?q=";
//$Search = $GoogleBase.urlencode($address);

/* Assemble code to generate map via the Google Maps API */
//$content = '<h3><a href="'.$Search.'" target=_blank>'._PAGESETTER_CLICK_GOOGLE.'</a></h3><br />';

$content = '<BR><BR><script src="http://maps.google.com/maps?file=api&v=1&key='.$key.'" type="text/javascript"></script> ';
$content = $content.'<div id="map" style="width: 500px; height: 400px"></div> ';
$content = $content.'<script type="text/javascript"> ';
$content = $content.'setTimeout("ShowGoogleMap()", 100);';
$content = $content.'window.unonload = "GUnload()";';
$content = $content.'function createMarker(point, number){ var marker = new GMarker(point);var html = "<b>" + number + "</b>";GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(html); }); return marker;}';
$content = $content.'function ShowGoogleMap(){';
$content = $content.'var map = new GMap(document.getElementById("map")); ';
$content = $content.'map.addControl(new GSmallMapControl()); ';
$content = $content.'map.addControl(new GMapTypeControl()); ';
$content = $content.'var point = new GPoint('.$long.', '.$lat.');';
$content = $content.'map.centerAndZoom(point, 4);';
$content = $content.'var marker = createMarker(point,"'.$me.'");';
$content = $content.'map.addOverlay(marker);';
$content = $content.'}';
$content = $content.'</script>';
echo $content;
?>3. Feel free to embellish. Donít
Reply With Quote
  #11  
Old 09-18-2007, 10:22 PM
meme meme is offline
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

Anyone know how to implement this into Hot Property for each listing?

meme
Reply With Quote
  #12  
Old 09-23-2007, 11:30 PM
lifeform lifeform is offline
Junior Member
 
Join Date: Aug 2006
Posts: 7
Default For the subcategories

Excellent feature this one! Thanks a lot.

Is it possible to make a GOogle map in the same way and show all the listings in the specific subcategories?

Would also be nice to have ALL the listings marked off on a bigger map for the whole mtree-catalogue.
Reply With Quote
  #13  
Old 09-24-2007, 02:04 AM
lifeform lifeform is offline
Junior Member
 
Join Date: Aug 2006
Posts: 7
Default

BTW: I had some problems with norwegian street addresses as well on this one, but setting up maps.google.no solved everything.
Reply With Quote
  #14  
Old 10-22-2007, 02:34 PM
woonydanny woonydanny is offline
Mosets'd
 
Join Date: Aug 2007
Posts: 27
Default cannot get this to work for Australian addresses

ok, i cant seem to get this to work for Australian addresses.

First i tried the code posted above with maps.google.com and then with maps.google.com.au but still no luck. the co-ordinates for an address that should be in brisbane are out in the pacific ocean off japan.

why would this be happening? i dont see why it wouldnt be geocoding it correctly as google maps in australia works fine.

any help much appreciated
Reply With Quote
  #15  
Old 10-31-2007, 07:02 PM
Muaz Muaz is offline
Junior Member
 
Join Date: Oct 2007
Posts: 1
Default

Hi, This post of mine is very knowledgable and may enhance the information of the viewers , however I would like some specific information for myself. If someone can help me then please send me a private message. Best Regards,
Reply With Quote
  #16  
Old 11-07-2007, 11:17 AM
woonydanny woonydanny is offline
Mosets'd
 
Join Date: Aug 2007
Posts: 27
Default australian google maps integration?

any luck with australian google maps integration?
Reply With Quote
  #17  
Old 11-15-2007, 10:01 AM
Aussie777 Aussie777 is offline
Mosets'd
 
Join Date: Apr 2007
Posts: 24
Default

I think I have worked out why Australia isnt working but im not sure how to remedy it.

I think its do do with the negative latitude. Basically Au is the reverse of USA and i think this has something to do with it.

A USA geo is Lat 34.xxxx Long -86.xxxx
A AU one is Lat -38.xxxx Long 144.xxxx

Its the only fundamental diff I can find as AU works with all other Google mapping solutions and works from Mtree from the Map link.

Anyone have any thoughts as to why and if this could be the problem?

(Update) I found it.. and yes its sorta what I was thinking .. If you comment out the // on this line

//echo "lat: $lat long: $long"; //format: <coordinates>2.395988,48.819813,0</coordinates>

You will see the Lat and Long at the top of the map. When you test with a US listing it works fine but the Au one DOESNT bring up the - (negative) value in the echo result. Hence it wont work..

I had similar problem with field formatting in excel once and I will try and work a solution now but I am pretty sure once the field format is correctly picked up it should work anywhere on the planet. Without the - result in AU we are basically off Japan in the ocean

(UPDATE2 WORKING!!!)


Change line

if (ereg (".*<coordinates>([-]?[0-9\.]{7,11}),[-]?([0-9\.]{7,11}).*", $lines, $regs))

To

if (ereg (".*<coordinates>([-]?[0-9\.]{7,11}),([-]?[0-9\.]{7,11}).*", $lines, $regs))

And it works in AU now It should now work on any negaitve Latitude!

Cheers,
Matt

Last edited by Aussie777; 11-15-2007 at 12:35 PM.
Reply With Quote
  #18  
Old 11-15-2007, 01:18 PM
woonydanny woonydanny is offline
Mosets'd
 
Join Date: Aug 2007
Posts: 27
Default

thankyou thankyou thankyou.

cheers mate, makes sense and now works perfectly.

thanks again for your help
Reply With Quote
  #19  
Old 01-08-2008, 02:12 PM
tlearyus tlearyus is offline
Junior Member
 
Join Date: Nov 2007
Posts: 11
Default Display Error in IE 6.0

thanks heaps for everyone's help to get this working..all is good in Mosets tree 2.0.3 under Firefox, Mozilla but the map position is up near the top right hand corner of the screen in IE 6.0 ????

ANY HELP TO SOLVE THIS WOULD BE REAL GOOD !!

regards - glen
Reply With Quote
  #20  
Old 01-19-2008, 10:11 PM
auswireless auswireless is offline
Mosets'd
 
Join Date: Nov 2006
Posts: 7
Default

Just getting into playing with Joomla 1.5 will this work with mosets and 1.5?
Reply With Quote
  #21  
Old 02-11-2008, 03:44 PM
redzer redzer is offline
Mosets'd
 
Join Date: Sep 2007
Posts: 6
Default

Great Thank. one question, how do I control the possition of the map?
Reply With Quote
  #22  
Old 02-26-2008, 01:52 AM
3bweb 3bweb is offline
Mosets'd
 
Join Date: Feb 2008
Posts: 85
Default

I just enabled mambots in the Description and used the GoogleMaps Plugin mambot - no probs!
Reply With Quote
  #23  
Old 03-05-2008, 07:26 AM
tlearyus tlearyus is offline
Junior Member
 
Join Date: Nov 2007
Posts: 11
Default

so how do you link this to each listing automatically without having to manualy enter the address co-ordinates for that listing ?
Reply With Quote
  #24  
Old 03-18-2008, 01:17 PM
dknight dknight is offline
Mosets Team - Lead Developer
 
Join Date: Dec 2004
Posts: 25,985
Default

FYI, a new field type for Mosets Tree 2.0 is available to embed Google Maps to your listing details. No code hacking required:

http://forum.mosets.com/showthread.p...3977#post23977
__________________
Lee
Lead Developer
Mosets.com - Quality Joomla! Solutions
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Maps and Mosets Tree ekal 3rd party addons & Custom Jobs 7 12-14-2010 05:26 PM
Joomla! Extensions Directory launched with Mosets Tree dknight Announcements 0 03-06-2006 05:23 PM
Mosets 1.50 released dknight Announcements 5 07-28-2005 12:26 AM
google (and other SE's) and mosets tree gmf Mosets & Joomla 0 02-20-2005 11:26 PM


All times are GMT +8. The time now is 07:53 PM.

Copyright © 2005-2010 Mosets Consulting

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.