automatic panning google map - javascript

I have a marker on google map v3, indicating a position of a vehicle. The marker moves, indicating the movement of the vehicle. How can I automatically pan the map, when marker tries to go out of the visible part of the map?

You can use the getBounds function of the map to query for the boundaries. If your point is moving outside the boundaries, you can simply call setCenter to update your map.

Related

LeafletJS handle markers on continuous map

I am seeing one problem with the LeafletJS map that the map is continous (infinite) to East and West. Howerver, it does not handle marker positions right. When I set a marker and focus on the marker I for sure see it in the right place. But when I rotate the map 1x around it's axis and arrive at the very same position, the marker is not there.
This is a problem when someone in Los Angeles for instance pans west to see his marker in Sydney, Australia, the marker does not appear. He has to pan east all the way to see the marker. Any solution to this?
Enable the worldCopyJump option when you are creating your map.
worldCopyJump
Boolean false
With this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible.

Center of google map changes after placing markers

I am initializing a google map using a GeoLocation service to set the initial latlng. The map is draggable, and dragging changes the center of the map.
I can place markers from a DB successfully, however doing so always changes the center of the map back to the original latlng (from geolocation).
I would like to be able to drag the map (changing the center), then place the markers, but leave the center of the map at the location to which it was dragged.
I'm not sure why running the function to place the markers (even when there are no markers in the DB to place!) always causes the map center to revert to when it was first initialized...
Any help much appreciated!
I think you can use setCenter function to change the center after setting up the marker. Something might be resetting the center when you are setting up marker (which is difficult to say without seeing your code), but you can always set the center manually.
setCenter(latlng:LatLng|LatLngLiteral)
You can use MarkerOptions to set marker to which you can provide Map. While providing the map, just set center of this map.

Moved marker disappears when using Marker Clusterer

I have an application that has a large number of markers (hence the desire to use Marker Clusterer), but I want to allow the user to move the marker around. Unfortunately, the marker disappears after it has been moved and you zoom out / in. Precisely, these are the steps that reproduce the problem:
Create all the markers / add them to a marker clusterer object.
Zoom in to see an individual marker.
Move the marker to a new location.
Zoom out until the clustering kicks in (and groups the moved marker with at least one other marker)
Zoom back in to see the marker that was moved.
I would expect the marker to still be there after zooming back in, but it is not. After step 3, the marker remains visible -- it only disappears after zooming out and then back in. The clustering still counts the marker correctly (it appears in the cluster total when zoomed out), but the marker doesn't ever appear again.
I have tried using the latest versions of MarkerClusterer and MarkerClustererPlus and I'm dealing with v3 of the maps API. Additionally, I have an event listener that calls repaint on the cluster after a marker dragend occurs (thinking that a repaint would cause the marker to be placed proper).
[Edit]
A minimal example (based on the Marker Clusterer example) that demonstrates the problem can be found here. The only things changed from this example are the lines including the javascript libraries (made absolute links), and adding draggable: true to the marker options. Following the above 5 steps should reproduce the problem.
This is a bug that has been reported to the google maps api team (issue # 167). See here
It is triggered any time by a setMap(map) followed by any sort of marker movement (including animation) followed by a setMap(null). At that point the marker cannot be shown again.

Constraint visible and pann-able area of google maps

I'm displaying a custom layer on top of the standard google map (v3). Now the users can pan out of the extents of my custom layer.
Is it possible to constrain the viewable area to a square given by the top-left and bottom right coordinates?
What you could do is prevent the user being able to pan the map at all. Set draggable:false in the mapOptions, and perhaps remove the pan control as well - panControl:false
Another idea; you could allow the user to drag/pan the map, but then if they move it outwith your bounds, you could call the panToBounds function on the map to move it back to where you want it.

How to displace markers at the same position in google maps?

How can I add a listener to google maps so that When it already has marker at say position x,y then another marker when added to the map to the same location will displace both the new and old markers in the vicinity of x,y so that they dont overlap.
also for e.g. there are 2 markers close but not overlapping, we add a third marker overlapping on of them, then we displace all three to form an equilateral triangle.
I ran into this issue also, Diodeus is correct that if you want to actually move one of the markers locations you would have to keep a store of your markers and as you are getting ready to plot check if that specific lat lng has already been plotted, if so at that point you would adjust the lat lng. The problem I ran into was that then one of your markers is in an incorrect location and/or it is still not viewable depending on the degree of zoom in correlation to the displacement that you add to your lat/lng.
I would recommend looking into marker clustering personally. This seems to be the route to go in these situations if you don't want to have a marker on your map with the incorrect location and still want the end user to be able to know that their are multiple markers on the same location.
Hope this helps.

Categories