Making Google map marker mouse-over more interactive - google-maps

I have a map with a google marker, but I would like to do some fun things with it like post a link in there, and format the text there to have an information item per line instead of all in one line.
Is that possible? If so, then what can be done and how? :)
Here is my current boring map and marker at the bottom of this page:
http://www.comehike.com/outdoors/parks/trailhead.php

You could do:
<script...
var marker = new GMarker(point);
map.addOverlay(marker);
var myHtml = "<your html here/>";
GEvent.addListener(marker, 'mouseover', function() {
map.openInfoWindow(point, myHtml);
};
.../>
where
<your html here/>
is what you want to show, for example image and contact info or something.
That is if you want the info window opened on mouseover event. You could either open it by default by calling that function ( map.openInfoWindow(point, myHtml) ) right away.
Hope that helps.

Related

Google Maps V3 Infobox undefined on polygons

I have a spoke in my wheels and I am not sure how to sort this out. I have been struggling with it for a couple days and it isn't like a normal infobox as it is not set to a marker rather a polygon which is something new for me. I have polygons that display with data from an XML file and they show up fine. I have searched the web and got it to have the mouseover set up to where you mouseover a polygon the opacity changes and an infobox pops up. Problem is the infobox when it pop up shows "undefined" instead of the html I have set in it to display with data from the XML file.
Here is a link to the test map for example.
http://www.mesquiteweather.net/googlemap_poly.html
Here is a link to the XML file where I am just trying to show the elements events and expires in the info box.
http://www.mesquiteweather.net/xml/warnings_test.xml
This is the code I am working with to create the infoboxes and mouseover events
function attachPolygonInfoWindow(polygon, html, event, expires)
{
var html = "<strong>" + event + "</strong>";
eventWarnings.infoWindow = new google.maps.InfoWindow({content: html});
google.maps.event.addListener(eventWarnings, 'mouseover', function(e) {
var latLng = e.latLng;
this.setOptions({fillOpacity:80});
polygon.infoWindow.setPosition(latLng);
polygon.infoWindow.open(map);
});
google.maps.event.addListener(eventWarnings, 'mouseout', function() {
this.setOptions({fillOpacity:0.35});
polygon.infoWindow.close();
});
}
var polygon = new google.maps.Polygon(/* omitted for brevity */);
attachPolygonInfoWindow(eventWarnings);
eventWarnings.setMap(map);
}
});
I am pretty sure it is something easy I am overlooking but I haven't been able to find anything that pertains to my issue. I am just lucky I got the infobox to show at all as I have learned it's tricky since polygons don't have a true center and they are not set up like you would with a marker which I can handle.
If anyone has any suggestions please let me know.
-Thanks
You defined your attachPolygonInfoWindow function with 4 argument, but only provide one when you call it:
// definition
function attachPolygonInfoWindow(polygon, html, event, expires)
...
// call
attachPolygonInfoWindow(eventWarnings);
Probably you want (I don't see the html or expires parameters being used):
attachPolygonInfoWindow(eventWarnings, "", event, null);
The other option would be to change the definition to:
// definition
function attachPolygonInfoWindow(polygon, event, expires)
and the call to (assuming you are going to use "expires" for something):
attachPolygonInfoWindow(eventWarnings, event, expires);
As it doesn't look like you need to pass in that parameter (event is serving the function that I would expect it to serve).
Also, FYI, you have a "hanging comma" in your alertColors.js which make IE unhappy...
example

How to identify a google map marker on click?

I'm creating a Google Map from the developer API v3. It's populated with markers created dynamically from ColdFusion querying an MsSQL database.
<cfloop query="One">
<script>locations[<cfoutput>#One.userID#</cfoutput>
] = new google.maps.LatLng(<cfoutput>#One.latLng#</cfoutput>);
</script>
</cfloop>
I need a way to recognise the marker when its clicked so I can display address details in a box below the map and also higlight markers when a button is clicked lower on the page.
In general, you would typically assign your own custom properties to the Marker. Something like:
function markerClicked(e) {
console.log('Marker ' + marker.myData + ' has been clicked');
}
var marker = new google.maps.Marker(...);
marker.myData = 1; //this could be arbitrary data or even another object
google.maps.event.addListener(marker, 'click', markerClicked);
Adding custom data to any Google Maps API object has risks though. Google's code is obfuscated and the internal (non-documented) properties can and do change. Make sure your property is named in such a way that it won't conflict with any existing property or future property. Tip: Choose a property name longer than 3 letters.
If you are going to minify/compile/compress your maps code, then there are additional considerations.
What about :
google.maps.event.addListener(marker, "click", function (e) {
var clicked = this;
//...
});
This is pretty thoroughly documented/explained in the documentation.
https://developers.google.com/maps/documentation/javascript/overlays#InfoWindows
When you create markers, add dom listeners to the markers like this
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});

sencha touch -> google maps markers not responding to touch

I have another question which needs resolving as it is rather irritating. I have been working on an app for a while and i managed to get it working nicely.
Specifically, the google map feature is supposed to have markers which appear and when you click on them, the screen is supposed to zoom in and display some information regarding the marker. Now, I have coded this in and it works perfectly when you test it out on Chrome. But when I tried to port it over to the tab device itself (Samsun Galaxy), there is no activity whenever i try to touch the markers whatsoever.
I am rather baffled and miffed by this, as the action of touching the marker should be the same as clicking on it using a mouse, am I not mistaken? I was wondering if anyone else could give me any help with this, as it is something minor which is causing one hell of a hiccup for me.
The code I have added below:
var marker_icon = new google.maps.MarkerImage('images/map/' + thisIcon + '.png', new google.maps.Size(32, 32));
trafficMarker = new google.maps.Marker({
position: new google.maps.LatLng(TrfAl.lat, TrfAl.lon),
animation: google.maps.Animation.DROP,
map: mapPanel,
icon: marker_icon,
id: 'trafficAlertPanel' + i,
componentId: 'trafficAlertPanel' + i,
});
markerArray[i]=trafficMarker;
google.maps.event.addListener(trafficMarker, 'click', function(){
console.log('clicked!');
LoadIncidentMap(this.id.substring(17));
});
For some reason click events don't fire for taps on android and iOS. One work-around is to use the 'mousedown' event instead, which will fire on tap.
google.maps.event.addListener(trafficMarker, 'mousedown', function(){
console.log('clicked!');
LoadIncidentMap(this.id.substring(17));
});

Drupal: How do I create a link to open a GMap marker/popup from outside map?

I am using Views to create 2 things
1: Locations list (table) PAGE
2: GMap ATTACHMENT
What I'd like to do is link the location title in the locations list to marker/popup in the map.
I've found sites that allow me to do this outside of Drupal, but would like to keep the site "Drupal Friendly".
Any help/hints would be greatly appreciated!!
Cheers
The discussion on this page should answer your question.
http://drupal.org/node/791998
you just need to add this code below in relative tpl file of drupal.
"seeMap a" is achor link when we click then google map pop open.
This is code which trigger popup:
GEvent.trigger(Drupal.settings.gmap.auto1map.markers[i].marker, "click");
"auto1map" depends your setting.
This is the code for to move position top:
var _pos = $('#banner').position();
_pos_top = _pos.top;
$('html,body').animate({scrollTop:eval(_pos_top) - 50},500);
Main code:
$(document).ready(function(){
$('.seeMap a').each(function(i){
$(this).bind('click', function(){
var _pos = $('#banner').position();
_pos_top = _pos.top;
$('html,body').animate({scrollTop:eval(_pos_top) - 50},500);
GEvent.trigger(Drupal.settings.gmap.auto1map.markers[i].marker, "click");
return false;
});
});
});

overriding big popup on directions Google Maps

I've happily implemented v2 of Google maps to my site without a hitch, I also successfully perform a drive directions using GDirections.load().
What I need to do is stop the popup of the mini map when you select a particular step in the routing directions. So when the user clicks on say "step 3", instead of the default popup showing a mini map, I'd like to add a custom icon to that position.
Hope it makes sense
Thanks in advance guys.
You need to add a handler on the GDirections object for the addoverlay event:
GEvent.addListener(gdir, "addoverlay", onGDirectionsAddOverlay);
When your onGDirectionsAddOverlay handler is called you can iterate through the new markers and replace them with copies that open your custom info window:
for (var i = 0; i <= gdir.getNumRoutes(); i++)
{
var originalMarker = gdir.getMarker(i);
latLngs[i] = originalMarker.getLatLng();
icons[i] = originalMarker.getIcon();
newMarkers[i] = new GMarker(latLngs[i], { icon: icons[i], draggable: true, title: 'Kan flyttes' });
map.addOverlay(newMarkers[i]);
// add stuff to your newMarkers[i] click event...
// ..
// Now we can remove the original marker safely
map.removeOverlay(originalMarker);
}