You are here:  » Integrate Google Maps


Integrate Google Maps

Submitted by ssgupta on Sat, 2012-12-01 10:41 in

Is there any instruction (I could not find) written on integrating Google Maps with Price Tapestry script, e.g. for use with a hotels data feed. The feed has hotel address as well as latitude and longitude data. Thanks.

Submitted by support on Sat, 2012-12-01 11:53

Hi,

It's not something that's been covered, but if you have added, say, "lat" and "lon" as custom fields then it would be easy to implement Google Maps as an embedded object (IFRAME) on your product page with the lat and lon from the $mainProduct variable. Have a go with something like this within html/product.php:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/?ie=UTF8&amp;ll=<?php print $mainProduct["lat"]; ?>,<?php print $mainProduct["lon"]; ?>&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/?ie=UTF8&amp;ll=<?php print $mainProduct["lat"]; ?>,<?php print $mainProduct["lon"]; ?>&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ssgupta on Wed, 2013-03-13 11:41

Could you guide how to embed this data in the WordPress plugin. Thanks.

Submitted by support on Wed, 2013-03-13 12:10

Hi,

Sure! Within the WordPress plugin, the HTML would be added to your Product / Main template (wp-admin > Settings > PriceTapestry.org). Here, instead of using the PHP variables, you would use the custom field placeholders - in this case %DB_lat% and %DB_lon%, so the code you would need to add to your template would be:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/?ie=UTF8&amp;ll=%DB_lat%,%DB_lon%&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/?ie=UTF8&amp;ll=%DB_lat%,%DB_lon%&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Milano on Thu, 2014-10-23 08:40

Hi,
Google Maps working great... but how to add marker or marker with bubble info (with name and address)?
Thanks for any help :)

Submitted by support on Thu, 2014-10-23 09:06

Hello Milano,

Assuming you have the standalone Price Tapestry version working, having added to your includes/product.php template file similar to the following:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/?ie=UTF8&amp;ll=<?php print $mainProduct["lat"]; ?>,<?php print $mainProduct["lon"]; ?>&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/?ie=UTF8&amp;ll=<?php print $mainProduct["lat"]; ?>,<?php print $mainProduct["lon"]; ?>&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>

...all you need to do is add a new parameter to the iframe src URL called daddr (destination address) and Google will then add a green pin to the map at this location. The address value must be URL encoded, so assuming that you have added the custom field `address` to your site, and you're already using `lat` and `lon` fields as described above, then the following should do the trick:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/?ie=UTF8&amp;daddr=<?php print urlencode($mainProduct["address"]); ?>&amp;ll=<?php print $mainProduct["lat"]; ?>,<?php print $mainProduct["lon"]; ?>&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/?ie=UTF8&amp;daddr=<?php print urlencode($mainProduct["address"]); ?>&amp;ll=<?php print $mainProduct["lat"]; ?>,<?php print $mainProduct["lon"]; ?>&amp;spn=0.045174,0.110378&amp;t=m&amp;z=13&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Milano on Thu, 2014-10-23 10:38

It's working :) Thank you!

And one thing... Maybe I did something wrong but in newest PT this function, eg.:

<?php
 
print $mainProduct["lon"]; 
?>
is not working. I have changed "$mainProduct" to "$product_main" and now maps display correctly :)

Submitted by support on Thu, 2014-10-23 11:21

Hi Milano,

That's the correct modification for 14/06A, I changed the main product variable to $product_main in html/product.php for namespace consistency.

Cheers,
David.
--
PriceTapestry.com