Can I add a MyMap map to a google Map programatically?

867 views
Skip to first unread message

Francois R

unread,
Oct 19, 2010, 8:39:46 AM10/19/10
to Google Maps JavaScript API v3
Hi,

I'm trying to build an app to display one or more user "My
Maps" (eventually together with other Fusion Table content) in one
map.

I've made some progress exploring the Google MAPS V3 and the gdata
Maps APIs (google.gdata.maps.MapsService) but I'm not exactly where
I'd like to be.

I can add a MyMap as a KML layer but only using the "View in Google
Earth" link:
var ctaLayer = new google.maps.KmlLayer('http://maps.google.com/
maps/ms?ie=UTF8&hl=en&vps=1&jsv=286b&msa=0&output=nl&msid=abc.def');
ctaLayer.setMap(gMap);

Using gdata I can get the KML data for individual features with gdata
Maps code like :
var featureEntries = featureFeedRoot.feed.getEntries();
featureEntries[i].getContent().$t;
and then loop to add 1 marker per feature.

What I'm trying to achieve is to add a whole user map in a single
step. Something that would look like :
var featureKLM = featureFeedRoot.feed.getContent().$t;
var ctaLayer = new google.maps.KmlLayer(featureKLM);
ctaLayer.setMap(gMap);

This sound trivial and I may be close to it but I can't figure out the
proper syntax. I couldn't google a good example of how to get a KLM
set out of the gdata Map API.

The direction I'm going it is to get a KLM set of all Features of a
single MyMap and create a new map layer with its content. Is it the
right approach? Can I programatically get a KLM document for a user
MyMap?

Any help will be appreciated.

Regards,

Joseph Elfelt

unread,
Oct 19, 2010, 7:41:46 PM10/19/10
to Google Maps JavaScript API v3
Good News - Yes you can.
I like having the ability to do this and I am surprised there is not
more chatter about displaying Google MyMaps via the API.

Step 1
Make a small KML file with a network link which points to the MyMap.
Put this small KML file online.
Here is an example file showing you how to point to the MyMap:
http://www.mappingsupport.com/p/gmap4/mymap/05/105432215366276592381.0004897737811ac6a6a05.kml
There is no magic in the file name itself. That name is just what I
happened to use.

Step 2
Write an API app to display that small KML file in the normal manner.
Here is an example using the small KML file cited above:
http://www.mappingsupport.com/p/gmap4.php?q=mymap,105432215366276592381.0004897737811ac6a6a05&z=14&t=t2

Francois Rioux

unread,
Oct 20, 2010, 6:45:50 AM10/20/10
to google-map...@googlegroups.com
Thank Joseph,

Nice things you've done on your site. A lot for me to learn.

For my purpose, I'd need something a bit more transparent.

I want users to pick markers from Map Searches or from other public MyMaps.  This would create their own entries (features) on a MyMaps the app would have previously created.
The Map they had build would also be available for the application.

For that reason, I wish I could dynamically display a MyMaps.  Your solution would work once a user has manually entered his 'View in Google Earth' link in the system so it can be saved in a Network Link.  What I'd like is to skip the manual step:  I'd like to browse a user's existing maps (I can already) and then display it based on his selection.  The gdata mapsService seems only to support the getKML method on the Feature entry, not at the Feed (map) level.

Thanks for your reply.  There is more to learn from your solution than just this particular point.

Francois



--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Joseph Elfelt

unread,
Oct 20, 2010, 9:34:58 AM10/20/10
to Google Maps JavaScript API v3
Thanks for the kind words.

You are correct. One premise of my app is that the user knows the
'msid' value (unique key) that Google assigned to the MyMap. I am
guessing that Google assigns an 'msid' value to each MyMap as soon as
the user saves the map. The trick for you will be trying to find a
way to learn those values.

Once you know the msid value for a MyMap then your code can build and
host the small kml file on the fly.

If you figure out a way to solve your problem without knowing the
msid values, please share it.

Good luck
Reply all
Reply to author
Forward
0 new messages