Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Joshua Asbury
Tip: Google Maps API Key For ASPs and The WOL
October 9, 2008 1:46 PM
Answer

Joshua Asbury

LIFERAY STAFF

Rank: Expert

Posts: 497

Join Date: September 8, 2006

Recent Posts

Here's a quick tip for anyone who is hosting multiple sites/domains under a single instance of Liferay. You can set the Google Maps API Key in the WOL's portlet.properties file, but that only allows you to set a single key. Sure, you can add a new property, etc. but a quick and easy (or is it quick and dirty?) way to go about that is modify the script that is written in the view.jsp for the Map.

OOTB, the code looks like this:
1<script src="http://www.google.com/jsapi?key=<%= PortletProps.get("map.google.maps.api.key") %>" type="text/javascript"></script>


You can modify the Javascript like this to dynamically add the API based on the referring domain:
 1
 2<script type="text/javascript">
 3      document.write(
 4         '<script src="http://www.google.com/jsapi?key=' +
 5         {
 6            'www.abc.com': 'KEY1',
 7            'www.xyz.com': 'KEY2'
 8         }[location.host] +
 9         '" type="text/javascript"><\/script>' );
10</script>


Maybe there is a cleaner way to go about it, but I thought that this could be useful for folks who are playing with the WOL.
Mika Koivisto
RE: Tip: Google Maps API Key For ASPs and The WOL
October 11, 2008 10:29 AM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1513

Join Date: August 7, 2006

Recent Posts

Maybe we should just add a possibility to set the API key through portlet preferences.
Stan X
RE: Tip: Google Maps API Key For ASPs and The WOL
March 29, 2009 9:31 AM
Answer

Stan X

Rank: Regular Member

Posts: 207

Join Date: January 27, 2008

Recent Posts

Thanks Josh (see). I cannot find a feature request on this. Have you created one?
Joshua Asbury
RE: Tip: Google Maps API Key For ASPs and The WOL
March 30, 2009 11:54 AM
Answer

Joshua Asbury

LIFERAY STAFF

Rank: Expert

Posts: 497

Join Date: September 8, 2006

Recent Posts

I never had created an LPS for this, but I just did. Please see http://issues.liferay.com/browse/LPS-2702