-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi! I want to insert google map in a zul file.
<div class="map-canvas" id="map-canvas">
<div class="map" id="map"></div>
</div>
In my .css file I have:
.map-canvas {
background-color: aqua;
min-height: calc(100vh - 50px);
padding: 0px;
}
#map {
position: absolute;
top: 0px;
bottom: 0px;
width: 100%;
}
and the js file contains:
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-33.8688, 151.2195),
zoom: 13,
disableDefaultUI: true
};
var map = new google.maps.Map(document.getElementById('map'),mapOptions);
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
infowindow.close();
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
window.alert("Autocomplete's returned place contains no geometry");
return;
}
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17);
}
marker.setIcon(({
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(35, 35)
}));
marker.setPosition(place.geometry.location);
marker.setVisible(true);
});
google.maps.event.addDomListener(window, 'load', initialize);
}
It doesn't work, the error message is Uncaught TypeError: Cannot read property 'offsetWidth' of null Any ideas?
Hi! I'm losing a lot of time on this problem, and I think the problem is in the following line code:
var map = new google.maps.Map(document.getElementById('map'),mapOptions);
I think the document.getElementById('map') doesn't get correctly the element. Is it possible?
Is there another way to get the element?
Thanks
Hello greendragon,
Why don't you use ZK's gmap component as shown below:
http://www.zkoss.org/zkdemo/reporting/google_map
Best Regards,
Darksu
Asked: 2015-09-24 15:15:11 +0800
Seen: 36 times
Last updated: Oct 19 '15