Obtaining latLng of cursor/mouse when triggered by a PolyMouseEvent - google-maps

I am new to the Google Maps API... so I apologize in advance if the answer to this question is somewhat basic... I have spent several hours trying to find a solution.
Explanation:
I would like to show an infowindow at the point the cursor was at when a click was detected while in a polygon.
I am able to open the infowindow - but am unable to determine the location to use.
It appears that the PolyMouseEvent object does not allow for getting the latLng like the MouseEvent does.
Is there a way to the the current mouse position (in latLng) in this case?

Set clickable:false in the PolygonOptions and listen for the click event on the map itself.

Related

How do I create a click event on a "Default Info Window(s)" based on the marker info for google maps v2, in xamarin android?

First of all I'm still new in Xamarin and I am trying to create a click event for a default InfoWindow. The thing is, using the code below under MarkerOptions (i.e. .SetTitle, .SetSnippet), will generate a default InfoWindow when I click on the marker, without creating or making any changes (custom InfoWindow) on xml.
Marker info
LatLng latlng = new LatLng(4.887746, 114.943652);
MarkerOptions options = new MarkerOptions()
.SetPosition(latlng)
.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.icon))
.SetTitle("title1")
.SetSnippet("address");
marker1 = gmap.AddMarker(options);
marker2 = gmap.AddMarker(new MarkerOptions()
.SetPosition(latlng2
.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.icon))
.SetTitle("title2")
.SetSnippet("address"));
However, my problem is that I don't know how to create a click event for each and every marker. For example, marker1 will open Activity1 and marker2 will open Activity2.
My question is, is it possible for me to create a click event, for each and every marker info, based on a default InfoWindow? I did try out using the OnInfoWindowClick for a Custom InfoWindow, and it worked well. But I'm still wondering if it can be done using a default InfoWindow, generated from the code above.
I did check other forums and different sites and still couldn't seem to figure how to code it in xamarin. I think it may be a small problem that I might've missed out, but if anybody can share their code to show the info window based on the marker's position, I would be very glad. I'm open to any other suggestions and best solutions you guys may have thought of.
Hope you guys can help me, thank you in advanced.
The GoogleMap class has a InfoWindowClick event that you should hook up to listen to click events on the Info Window.
gmap.InfoWindowClick += HandleInfoWindowClick;
private void HandleInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
{
var marker = eventArgs.Marker;
// do stuff...
}
This will create a single event handler that reacts to all markers.
Xamarin has a nice sample on how to use Google Maps on GitHub in their samples repo.

Google Map - Which event when click on a place

Sorry for my bad English!
I have spent more than a day for web search about this, but i have not found the solution yet. Please give me a suggestion.
I'm now working with google maps api. I've got a place autocomplete sample here: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete
As the attached image, the place autocomplete feature works perfectly. When I enter the key word [Sydney distance education] --> click on the first suggestion --> the marker was moved to the specified place. I can get more detailed information from the marker variable.
This is the screen: http://www.imagesup.net/pt-1314056232011.png
When i click to the specified place on the map, it display a InfoWindow. I don't know which event should I need to listen to help me getting more detailed information of that place.
I have tried this
google.maps.event.addListener(map, 'click', function(event) {
alert('OK');
});
But the event is fired only when I click to another location which does not have viewport

Draw area/polygon and retrieve coordinates with google maps

Is there any tool that can help me with getting the coordinates for a specific area/polygon?
I usually use Google Earth.
Draw a polygon, then move the mouse over and right click > copy.
Then you can paste it in the notepad and you will find the coordinates there (remeber the format (long, lat,n) the reverse of Google Maps format.
You can also use online tools to format the information or remove parts.
http://www.earthpoint.us/Shapes.aspx
So the idea is to have a map, draw a polygon on it (I assume by placing the vertexes) and then getting the coordinates of the vertexes?
You can make markers draggable when you create then. You can also get the lat/lng position of the markers when certain events fire: the 'dragend' event, for instance.
With these tools, you have the basics of your requirements here. Make a button that places vertexes on the map - just use a marker with custom graphics - and let the user drag the vertex to whatever position they need. Record the new position of the vertex whenever the dragend event fires. Draw lines on the map between the markers, to show to the user the area selected. Have a button to 'complete' the shape, linking the last vertex up with the first vertex.
There may be some existing code to do this, but I am not aware of it. However, it should be possible to throw something together with a bit of work.

Google maps and raising marker

I'm writing web app that uses google maps. I've got some points placed to the map as markers. When I drag the marker - it raises - and when I drop it - it falls back down. I want to avoid raising marker. Is there any way to drag it without raising?
This feature has probably been added since the question was asked but stopping the marker from raising is quite straight forward now.
When creating Marker set its 'raiseOnDrag' property to false. Like so...
marker = new google.maps.Marker ({draggable : true, raiseOnDrag : false});
Since there is no option while creating the marker I guess there is no way.
The only thing, I could imagine would be using the icons (in the reference there is an example).
But you have to try, I don't know if selfmade icons are raised or not.
You can use marker.setAnimation() method:
var marker = new google.maps.Marker({...});
google.maps.event.trigger(marker, 'dragstart'); // trigger dragstart to keep marker in the "raised" state"
marker.setAnimation(3); // raise
// later
marker.setAnimation(4); // fall
In Google Maps API there are only two types of animations documented (BOUNCE and DROP), but I have discovered two more:
1: BOUNCE,
2: DROP,
3: raise,
4: fall

Snap to nearest street

You guys have been helping out solving some of my problems with a Google Map lately, and thank you for that.
I am almost done with this - only one problem is left. When I place the first marker on the map, it snaps to the nearest street (which is fine!) but when I drag the first marker to another place, directions suddenly mess up. And the markers get mixes.
You can see an example on http://dev.korebogen.dk/gmap/
I need to make it possible to move the first marker (still snapping) and when I place the second marker, the directions first load. But in order to make the first marker snap again, I have to load the directions.
I hope some of you have a solution. Thanks in advance.
Blackpool Community Church Javascript Team has an excellent example of exactly this (direct link to the fourth example). Check out their other examples as well.
(disclaimer: I'm not affiliated with them, but have learned a lot about GMaps from their examples)
Edit:
I suspect the map events fire somewhat like this (pseudocode, for real event names etc. check the GMaps docs):
map click: mousedown, mouseup, click:{set red marker}
drag red marker: mousedown, dragstart{red marker}, mouseup, click:{set marker b} (mousedown+mouseup), dragend
both markers are set? Yes, get directions
What I'd suggest: in red-marker and marker-A dragstart functions, set some flag "dragging a marker", reset it in dragend function; in the Set marker B function, only set marker if we're currently NOT dragging something (flag is not set).
The code I gave you previously listened for the first two clicks, and added a marker for each. The problem is that when you drag the first marker, it's calling the "click" event again - and thus adding another marker at the same location.
Fortunately, the click event lets you know whether an overlay was clicked. So only execute the code that adds a new marker if overlay is null. Note that overlay is not a boolean.
var listener = GEvent.addListener(map, "click", function(overlay, latlng) {
if (overlay == null) {
// code to add new marker
}
});