Google Maps marker is set draggable, but cannot drag it - google-maps

API v3
I have a strange issue with a marker:
The marker that I place on the map is set to be draggable, WebInspector reports it as being draggable, but I still can't drag it. The cursor doesn't change when I go over the marker.
The underlying map is draggable, and that works.
On another page, with a different setup (less layers), but the same javascript, it works as expected (so there I can drag it).
I also made the marker clickable and bound an event to it, and that works fine. The cursor changes as well on mouseover.
I have run out of options.... Why can I not drag it? Can this have to do with some zIndex or layer positioning? As far as I can see, the map has a higher zIndex than all the other layers....
// display map
geocoder.geocode( { 'address':address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// map options
var mapOptions = {
zoom: 14,
center: results[0].geometry.location,
panControl: false,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false
};
// render map
map = new google.maps.Map(J('#'+mapElementId)[0], mapOptions);
// set marker
marker = new google.maps.Marker({
clickable: true,
draggable: true,
icon: markerImage,
shadow: markerShadow,
shape: markerShape,
map: map,
position: results[0].geometry.location
});
google.maps.event.addListener(marker, 'click', function () { alert('marker clicked'); });
google.maps.event.addListener(marker, 'dragend', function () {
alert('marker dragged')
map.setCenter(marker.getPosition());
J('input[name=coordinates]').val(marker.getPosition());
J('input[name=address]').val('');
});
J('input[name=address]').val(results[0].formatted_address);
}
});

you have draggable: false,.
change it to true
see it working here: http://jsfiddle.net/RASG/vA4eQ/

Try this:
map.setOptions({draggable: true});

Related

Google Maps KML zIndex property not changing layer display order

Question
Why doesn't changing the zIndex values for my KML layers change which layer is plotted on top?
Working example
According to the documentation the KmlLayerOptionsIterface has a zIndex property.
However, in this example, no matter which layer I set as zIndex: 1 and zIndex: 2, the circles are always displayed on top of the polygons
var map;
var kml1 = 'http://www.energy.ca.gov/maps/renewable/BuildingClimateZonesMap.kmz';
var kml2 = 'http://www.energy.ca.gov/maps/renewable/renewable_development.kmz';
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(-19.257753, 146.823688),
zoom: 2
});
var kmlLayer1 = new google.maps.KmlLayer(kml1, {
suppressInfoWindows: true,
preserveViewport: false,
map: map,
zIndex: 2
});
var kmlLayer2 = new google.maps.KmlLayer(kml2, {
suppressInfoWindows: true,
preserveViewport: false,
map: map,
zIndex: 1
});
}
Working JSFIddle
Should changing the zIndex values change which layer is displayed on top?

Draggable: false doesnt appear to be working on Google maps

We are currently using two google maps on one page, the first one is an aerial view, and this I can turn off draggable and it works fine. The other is an internal view of the building, when I use the same code on this, it doesnt disable draggable on mobile or on desktop, I can disable scrollwheel movement, but not draggable. The code I am using is below.
function initialize2() {
var fenway = new google.maps.LatLng(0, 0);
var mapOptions = {
center: fenway,
scrollwheel: false,
zoom: 8,
draggable: false
};
var panoramaOptions = {
position: fenway,
scrollwheel: false,
draggable: false,
<?php echo(isMobile()) ? 'draggable: false,' : ''; ?>
pov: {
heading: 180,
pitch: 0
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById('map-canvas2'),panoramaOptions);
map.setStreetView(panorama);
}
google.maps.event.addDomListener(window, 'load', initialize);
You just need to add: draggable: false like this
// Function to initialize the map within the map div
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 27.963989, lng: -82.799957},
zoom: 14,
draggable: false
});
}

Google Maps: set zoom in options

Im using Google Maps, I added 2 markers.
Online Demo:
http://jsfiddle.net/VnwFT/1/
I just need to set a zoom, I tried in mapOpts and in fitBounds as well:
zoom
minzoom
maxzoom
e.x:
var mapOpts = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true,
scrollwheel: false,
zoom: 16
}
and it doesn't work.
How Could I set a zoom?
See what I've done here:
http://jsfiddle.net/VnwFT/27/
First you need to define the center of the map when you initialize it:
var mapOpts = {
center: new google.maps.LatLng(45.764043,4.835659),
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true,
scrollwheel: false,
zoom: 16
}
Then if you don't need the fitBounds function (the center of the map is already defined on initialize), you could comment it.
Then in the marker click listener you could edit the code to zoom the map on marker click:
google.maps.event.addListener(pushPin, "click", function () {
infoWindow.setOptions(options);
infoWindow.open(map, pushPin);
if (this.sidebarButton) this.sidebarButton.button.focus();
map.setZoom(16);
});

Disable movable Gmap

is it possible to disable the move inside of a google mal (v3) for the time i drag a marker?
I don't want to use i.e. the static map. I need the generall function of movement, but for the moment I drag a marker, the map should not move.
Thanks a lot!
Markers have dragstart and dragend events. On dragstart, disable the "movement" functionality on the Map by setting various MapOptions to false, like draggable, scrollwheel, etc. On dragend, set the MapOptions back to true.
Here is a function you can use to disable or enable map movement based on a boolean. It assumes your Map variable is map.
function disableMovement(disable) {
var mapOptions;
if (disable) {
mapOptions = {
draggable: false,
scrollwheel: false,
disableDoubleClickZoom: true,
zoomControl: false
};
} else {
mapOptions = {
draggable: true,
scrollwheel: true,
disableDoubleClickZoom: false,
zoomControl: true
};
}
map.setOptions(mapOptions);
}
And then you use this in your events like this (marker is your Marker variable):
google.maps.event.addListener(marker, 'dragstart', function() {
disableMovement(true);
});
google.maps.event.addListener(marker, 'dragend', function() {
disableMovement(false);
});
gmap.setOptions({'scrollwheel': false});

Google maps KM bounds box reapplying itself on map zoom

I have a map in which I apply a custom overlay using KMbox overlay to signify where I think the users general point of interest lies. What I want is to display this map to the user and allow them to click on the map to give me an exact location match of their POI.
This all works fine except for when the user clicks on the map and changes the zoom of the map.
Here's my code to add the marker to the map.
function addMarker(location) {
if(KmOverlay)
{
KmOverlay.remove();
}
if(last_marker)
{
last_marker.setMap(null);
}
marker = new google.maps.Marker({
position: location,
map: map
});
// Keep track for future unsetting...
last_marker = marker;
}
And to show the map I have this function.
function show_map(lt, ln, zoom, controls, marker)
{
var ltln = new google.maps.LatLng(lt, ln);
var vars = {
zoom: zoom,
center: ltln,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: controls,
navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN} ,
mapTypeControl: false,
scaleControl: false,
scrollwheel: false
};
map = new google.maps.Map(document.getElementById("map_canvas"), vars);
KmOverlay = new KmBox(map, new google.maps.LatLng(lat, lon), KmOpts);
var totalBounds = new google.maps.LatLngBounds();
totalBounds.union(KmOverlay.getBounds());
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng);
});
}
I have a working example at the following link here
fixed this by using the setMap() method on the KmOverlay and passing null as a parameter.
eg:
function addMarker(location) {
if(KmOverlay)
{
KmOverlay.setMap(null);
}