Hi Blane,
You could do something like:
var mapDiv = document.getElementById('map-div-id');
var map = new google.maps.Map(mapDiv, myOptions);
mapDiv.map = map;
then later you can get the map by doing:
document.getElementById('map-div-id').map
I'm just writing this off the top of my head so it might not work in all
browsers.
- Luke
On Thu, Apr 22, 2010 at 7:30 AM, Blaine <[email protected]> wrote:
> Yes, I am and that does work when I know how many maps are going to be
> on a page but I've made my map function generic enough to use on
> multiple maps on the same page.
>
> I have looked into making a 2 dimensional array to store map var | div
> id, but I was hoping there would be a way to get a reference to the
> map in the div with only the div id. This is one of those situations
> where I can force it to work, but I would just like something a bit
> more elegant.
>
> Any ideas?
>
>
> On Apr 21, 7:49 pm, Jason Sanford <[email protected]> wrote:
> > Hi Blaine
> > It sounds like you might be declaring your map variable inside a
> function.
> > Try declaring it outside of a function and initializing inside like so:
> >
> > var map;
> > function initialize() {
> > var myLatlng = new google.maps.LatLng(-34.397, 150.644);
> > var myOptions = {
> > zoom: 8,
> > center: myLatlng,
> > mapTypeId: google.maps.MapTypeId.ROADMAP
> > }
> > map = new google.maps.Map(document.getElementById("mapCanvas"),
> myOptions);
> > }
> >
> >
> >
> > On Wed, Apr 21, 2010 at 6:43 PM, Blaine <[email protected]> wrote:
> > > I have a div with id="mapCanvas"
> >
> > > I create a map inside the div
> > > var map = new google.maps.Map(document.getElementById("mapCanvas"),
> > > myOptions);
> >
> > > Assuming that the function that creates the map has completed and I
> > > have now lost the map var.
> >
> > > How do I get a reference back to the existing map when I only know the
> > > div it is in?
> >
> > > var oldmap = document.getElementById("mapCanvas").theMapInisdeThisDiv;
> >
> > > --
> > > 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
> > > [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected]<google-maps-js-api-v3%[email protected]>
> <google-maps-js-api-v3%[email protected]<google-maps-js-api-v3%[email protected]>
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-maps-js-api-v3?hl=en.
> >
> > --
> > 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
> [email protected].
> > To unsubscribe from this group, send email to
> [email protected]<google-maps-js-api-v3%[email protected]>
> .
> > For more options, visit this group athttp://
> groups.google.com/group/google-maps-js-api-v3?hl=en.
>
> --
> 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
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-js-api-v3%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.