i have these two lines
map.panTo(respectiveMarker.getPosition());//Center in map the respective marker
infoWindow.open(map, respectiveMarker);
When infoWindow.open is executed the map pans to the edge.
If i remove this line the map pans to the marker as expected.
Any ideas?
You should set disableAutoPan to be true in the InfoWindow and that will stop the map from moving when the infowindow is open.
Related
Have a huge problem, searching for weeks now. I have many markers and big InfoWindows per marker that most of time don't show up completely in my map-bounds. How to move the map automaticly and show these big InfoWindow exactly in the center? Further I think of showing it not only in the center (because the InfoWindows are more long than broad) but, say, in a lower position of center (centered, but near to bottom on the map-bounds). I hope you understand, what I mean.
Further, my InfowWindow even changed in size after I click on a link in it and get even bigger (o my god ;-), so I also have to handle this also.
You probably know that InfoWindow has an option disableAutoPan, but it's defaulted to false so that you should automatically see it whenever it's opened. If you want it in the center, then your best bet is in the click event before opening the InfoWindow, to center the map on the marker first. The autopan from opening should handle automatically and adjust the viewport to fit the InfoWindow from there as necessary.
//marker and map defined somewhere already
var iw = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function(){
map.setCenter(marker.getPosition());
iw.setContent('your content');
iw.open(map,marker);
});
I have a Google Maps JavaScript v3 map on my website that allows me to drag the marker to get the coordinates for the given location. This works perfectly but I also want to enter the coordinates manually and then click on a link to update the marker. This works great but I can't center the map to the marker (make it to pan to the marker).
I have also added a select box with solid coordinates to quickly get to a specific location on the map. I have the same problem for this one to as for the first problem.
The problem is that when I manually enter the coordinates or choose a fixed location, the marker only moves few steps from the origin position or it doesn't move at all. When you try to grab the marker and move it you can't move it and the X is far away from the marker. After few attempts to move the marker the maps goes blank but the marker stands still.
You can see my solution and problems on jsFiddle. How can I fix my issue?
Thanks in advance.
function moveMarker() {
var lat = parseFloat(document.getElementById('marker-latitude').value);
var lng = parseFloat(document.getElementById('marker-longitude').value);
var newLatLng = new google.maps.LatLng(lat, lng);
marker.setPosition(newLatLng);
map.setCenter(newLatLng);
}
Does that work?
I hope you can help. I have a two pronged problem but I'm pretty new to javascript and the google maps API (v3) so please be gentle.
What i'm trying to do is add a marker to a map based on an address eg. Geocoding, then wherever that marker is, draw a circle around it at a radius of 5km. I've found some code to do the circle, and also the geocoding and both are working together nicely.
The problem is, I'm wanting to make the marker draggable to a new location and once at the new location, remove the old circle, and draw a new circle.
To understand what i'm trying to achieve, have a look at http://www.gleff.com/test/
With the above example, if you geocode an address, it centers on the marker location and draws the circle. I want to drag the marker somewhere else, and both remove the old circle, and draw the new circle based on the new location. At the moment, it just drags the marker to a new location but the circle stays where it is.
I assume the best approach is to drag the marker, then remove the overlay of the circle, and then re-add it at the new location.
Problem 1. How to remove the circle (overlay)
Problem 2. How to re-add it at the new location after dragging the marker
I've tried a number of things such as adding markers to an array eg. var markers = [];
and then trying to clear the overlays using this as an example.
http://code.google.com/apis/maps/documentation/javascript/examples/overlay-remove.html
I've been unsuccessful because I'm probably not putting the code in the correct place.
I've experimented with the overlay removal code in multiple parts of the javascript but nothing seems to work. Rather than go through all the locations of the code i've attempted to add the code to, i've purposely removed all reference to it to make it easier to understand.
So.. Can anyone offer any assistance? I just want to draw the circle around a marker, and then be able to relocate that marker (including the circle). But I want to understand how to remove the circle as well because ultimately, I will have multiple markers and will want to remove individual markers (including the circle) permanently from the map.
Note: I'm pretty sure I can work out how to remove the markers themselves, but the circle just doesn't want to be removed. If I geocode an address twice for example, the circle just draws a second time making it darker, rather than be removed from the map, and re-drawn.
Any assistance would be great.
Thanks
Geoff
Note: The only code i've modified is in the main.js
I'm not familiar with the API but you could have a look at what events are available in the API when you start dragging the marker and also when you drop the marker. Creating event listeners that draw and remove the circle around the marker is the way to go. I'm sorry I can't help you with WHAT event you need to listen for...
This gives a movable marker with circle overlay bound to it
function init() {
var mapCenter = new google.maps.LatLng(56, -4);
var map = new google.maps.Map(document.getElementById('map'), {
'zoom': 10,
'center': mapCenter,
'mapTypeId': google.maps.MapTypeId.ROADMAP
});
// Create a draggable marker which will later on be binded to a Circle overlay.
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(56, -4),
draggable: true,
title: 'Drag me!'
});
// Add a Circle overlay to the map.
var circle = new google.maps.Circle({
map: map,
radius: 5000// 5 km
});
//Bind circle to marker
circle.bindTo('center', marker, 'position');
}
// Register an event listener to fire when the page finishes loading.
google.maps.event.addDomListener(window, 'load', init);
I have, for example, 10 markers on Google Map. But I zoomed and in visible area left only 2 markers.
Can Google Maps API somehow return me a number of markers in visible area (2 for my example)?
You can evaluate map.getBounds().contains(marker.getPosition()) with each marker to see which ones are included in the current viewport.
The above code is not working. There is no method as such getBounds(). Below is the updated code :
VisibleRegion visibleRegion = map.getProjection().getVisibleRegion();
LatLngBounds mapBound = visibleRegion.latLngBounds;
if(mapBound.contains(marker.getPosition()){
// do somethings i.e. such as changing marker icon and others.
}
I'm using GMap V3 API Circle to display the event location, if the more events occurs in that location, the size of the circle, i.e the radius would be bigger, in other words, the size of circle only relates to the event number occur in that location.
However, the radius of circle API is in meters on the Earth Surface, which means if I zoom in/out, the visual size of circle varies, so is there some function or formula to keep the circle size constant no matter which zoom level I'm in?
Thank you!
Ryan
I haven't seen any function to make the constant circle overlay on Google map. So the alternative solution which I am using that I have make the image of circle and then use the marker overlay with custom image on Google map. Following is the code of marker overlay.
var image = 'circle.png';
var beachMarker = new google.maps.Marker({
position: centerPoint,
map: map,
icon: image,
});