How To Get Some Information In Google Maps Without Click Event On Marker And Show This In A Div, Other Than Infowindow
Solution 1:
You can use the addDomListener event of the google maps api. Something like this:
<script>functioninitialize() {
// Map initialization
}
google.maps.event.addDomListener(window, 'load', initialize);
</script><body><divid="map_canvas"></div></body>
Although the above code is Maps Javascript API code, the addDomListener() method binds to the window object of the browser and allows the API to communicate with objects outside of the API's normal domain.
further reading
Actually the basic Idea is that you need to read an XMl and parse the data and and show this in a seperate div on right side., This div you can create dynamically when you load the map e-g:
$("#body").append("<div class='newdiv'></div>")
Solution 2:
From the google Docs in the section about InfoWindow:
Note that if you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindow options object.
So in your code, why don't you simply init your infoWindow and call the open()
method? I am not particularly familiar with the api, but how about:
var infowindow = new google.maps.InfoWindow({
content: 'your initial text'
});
infowindow.open();
Or if you need the marker for special purposes on the infowindow, init an marker with the center position and use that in the infowindow.open(your_initial_pos)
call.
Solution 3:
You can use jQuery to .triger()
a click
event on the first marker on document.ready
:
$(marker).trigger('click');
This will run the code you have already written and make it so when the page loads your div
will be populated with data from whatever element you trigger the click on.
When you bind to document.ready
you don't need encapsulate document
in quotes:
$(document).ready(function () {...});
Or you could use the short-hand if you're into that sort of thing:
$(function () {...});
UPDATE
You can place the trigger
function call after your for
loop where you are setting up the markers:
for(var i = 0; i<places.length; i++) {
var marker= new google.maps.Marker({
position: places[i],
map: map,
title: 'Place' + i
});
(function (i,marker){
google.maps.event.addListener(marker, 'click' , function() {
infowindow.setContent('PLace Number' + i)
infowindow.open(i, marker)
});
});(i, marker);
//only run on the first markerif (i === 0) {
//trigger a click event to show the first info-window
$(marker).trigger('click');
}
}
Solution 4:
You can fire a tilesloaded event on the map object. Check out the Map reference for events
tilesloaded waits until the map tiles are actually loaded before firing. Using your code, you could do something like this:
functionloadMap() {
var myLatlng = new google.maps.LatLng(40.46998, -3.68705);
var myOptions = {
zoom: 3,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
google.maps.event.addListener(map, 'tilesloaded', function() {
doSomething();
});
Post a Comment for "How To Get Some Information In Google Maps Without Click Event On Marker And Show This In A Div, Other Than Infowindow"