Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-03-18 20:21:43

Locutionist
Member
From: The mountains, central PA, USA
Registered: 2005-08-15
Posts: 57
Website

Google maps api integration

Greetings all. This may not be the best place to post this but you all have been very helpful over the years so perhaps someone can send me in the right direction.

I’m working on a rather large, textpattern-powered project for which I want to include a Google map. I will need the ability to search markers, allow website users to add markers on a moderated basis, categorize the markers, and use my own marker images, among a few other things. Ideally I would also like to make all the marker info available to others for use via XML, KML, OPML, or whatever formats seems most suitable.

I was planning to use CommunityWalk for this, but they have a 500-marker limit for performance reasons. This map will potentially have thousands of markers all over the world, so it will also have to use some sort of layering or selective zoom-level display to avoid the performance issues.

I’ve been reading the Google maps API documentation all afternoon, and while it’s given me a general idea of how the architecture for all this will work, I just don’t have time to learn how to code Javacript that fluently or how to integrate it with Textpattern’s PHP for adding markers and such.

This is part of a “green”/sustainable startup I’m bootstrapping and I’m looking at mid-May to launch.

If you’d like more information, please contact me directly at: paula [at] rabbit [hyphen] mountain [dot] com. Please feel free to pass this on to anyone you know who might be interested.

Thanks, —paula

Offline

#2 2008-03-18 22:40:06

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Google maps api integration

I can’t say that everything you want to do is possible in Textpattern, but here are some ideas …

I wanted to put up a blog on my overseas holiday with each article shown on the map, which would also show all the places I had visited.

Firstly, have a read of this page: Google Maps in Textpattern. The first thing I did was to implement this approach as a very basic start.

I then started modifying it from there:
  • allowed for the article excerpt to become the text in the popup,
  • allowed the map page to accept a category or section in the url, so the map could be limited to a subset of articles,
  • allowed the map page to accept lat and long as coordinates to centre the map on, and
  • bundled all the functions I needed in my own plugin.

I can’t comment on the output formats you want to use, or the issue of performance – not things I had to worry about. But the basics can be done.

PS. Unfortunately, I can’t show you the results of my work because in a mad moment I redesigned my site and still have to rebuild some of this stuff.

Offline

#3 2008-03-18 22:58:11

Locutionist
Member
From: The mountains, central PA, USA
Registered: 2005-08-15
Posts: 57
Website

Re: Google maps api integration

Ah thanks man, that could actually get me started with some of this stuff. I’m bookmarking that page at once.

—paula

Offline

#4 2008-03-19 19:19:48

Locutionist
Member
From: The mountains, central PA, USA
Registered: 2005-08-15
Posts: 57
Website

Re: Google maps api integration

Okay well that solution doesn’t work at all. I suspect there is some difference between the way the code was written when that post was new, and the way Google’s map API handles code now. So I am back to square one, and my original request still stands.

Thanks,
—paula

Offline

#5 2008-03-20 04:58:12

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: Google maps api integration

yeah – same as paula
will have to actually read the docs & figure it out

but aslasw66 … can u give an overview of how you passed the categories in the URL to the map? and were u able to click on a link in an article, and have the map page load with the article marker ‘open’ – or identifying itself in some way?

EDIT: fixed – I just didn’t allow for being in a subdomain
the instructional article is spot-on!

Last edited by nardo (2008-03-20 08:33:46)

Offline

#6 2008-03-25 11:31:32

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Google maps api integration

Sorry about the delay – long Easter weekend etc.

Here’s an overview of the functions I created for myself…

The first function in my plugin simply inserts the required script reference to Google Maps. It has one attribute – your API key.

The second function creates a text link to the map page. For me, it would say something like “See this on the map”. Apart from attributes for the link text and class, the tag would also accept names for any custom fields containing the longitude and latitude of the article ie. they could be named anything you like, but for me they were “lat” and “long”. The tag would build a text link with a URL string including “&center=” and the values from the custom fields.

The third function shows the map in place in a page. It has attributes for the height and width of the map, default zoom setting and class. It also has an attribute for the dimension of the Google Map popups. The tag then determines whether there is a “&center=” in the URL and assigns those values to variables. And then it puts together the complete script to display the Google Map using whatever attributes/variables can be found and centred on the lat/long passed in through the URL.

All of this worked for me, but error-checking was pretty minimal.

If you’re interested, let me know and I’ll send you the code – no warranty whatsoever, and no funny comments about my (lack of) coding skills.

Offline

#7 2008-06-12 18:41:36

azw
Member
Registered: 2007-01-29
Posts: 279

Re: Google maps api integration

aslsw66, that code would be very helpful. Could you please send me a copy or post it here? There’s no way in your profile to contact you.

Offline

#8 2008-06-13 02:45:11

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Google maps api integration

The code is available here. Please bear in mind that this is completely untested in the wild. It worked on my particular installation of TXP at the time, and that was good enough for me!

The first tag is called “as_gmap” and accepts a single attribute for the api key. This tag should be used in the <HEAD> section of your page.

The second tag is called “as_gmap_link” and should be used in an article form or page. It displays a link from the currently displayed article to the map. It has attributes of:

  • linktext – this is the text that will appear as the link. It defaults to “See this on the map”.
  • class – so that you can style the link.
  • latfield and longfield – these are the custom fields you have defined as holding the coordinates.
  • linkstub – this is a bit harder to explain. Following the example in David Ramos’ article, you create a page to display the map. The linkstub attribute is the URL for that page. It isn’t very smart, in that it doesn’t look for the basic site URL.

The third tag is called “as_gmap_show”. This tag accepts attributes of:

  • width and height – so you can fit the map to your layout.
  • class – so that you can style the map. It’s probably redundant as their is an id associated with the map anyway.
  • zoom – to define the zoom level. It defaults to ‘4’.
  • window_width – this is the width of the window for popups. I found the default was too large and it broke my layout.
  • data – this is the URL to the page that holds the XML information for the markers. Unlike linkstub above, this attribute does work from the basic site url.

So, it did work when I was using it, but some improvements could include:

  • fixing the linkstub so it works from the site URL instead of requiring the full URL to be coded,
  • being able to pull in data for certain categories. This would make it easier to have different maps showing markers for different categories, without having to create a separate section to hold the XML data for each category. This would mean modifying the XML page to accept categories through the URL and then only pull in article information for those categories.

AS

PS. Added the option to allow you to email me!

Offline

Board footer

Powered by FluxBB