tingel
Goto Top

GoogleMaps und KML

Hallo zusammen,

ich versuche, auf einer Webseite GoogleMaps darzustellen, welche auch Informationen aus einer KML-Datei anzeigen soll.
Klappt ja an sich alles, jedoch möchte ich auch einen fixen Mittelpunkt der Karte definieren. Ohne der KML-Datei klappt dies auch, aber sobald ich die KML-Datei miteinbinde, ist der Mittelpunkt leider verschoben.
Was muss ich machen, damit mein Mittelpunkt wieder greift?

Hier der Code:
<script type="text/javascript"   
	src="http://maps.google.com/maps/api/js?sensor=false">  
</script>
<div style="overflow:hidden;height:500px;width:600px;">  
	<div id="gmap" style="height:500px;width:600px;"></div>  
	<style>#gmap img{max-width:none!important;background:none!important}</style>
</div>

<script type="text/javascript">   
	var kmlsrc = 'http://domain.de/kml.kml';  
	function init_map(){
		var myOptions = {zoom:17,center:new google.maps.LatLng(46.94117,13.802050000000008),
		mapTypeId: google.maps.MapTypeId.SATELLITE};
		map = new google.maps.Map(document.getElementById("gmap"), myOptions);  
		loadKmlLayer(kmlsrc, map);
		marker = new google.maps.Marker({map: map,position: new google.maps.LatLng
		(46.94117, 13.802050000000008)});
		google.maps.event.addListener(marker, "click", function(){  
		infowindow.open(map,marker);});}google.maps.event.addDomListener
		(window, 'load', init_map);  

	  	function loadKmlLayer(kmlsrc, map) {
	  		var kmlLayer = new google.maps.KmlLayer(kmlsrc, {
	    		map: map
	  		});
}

</script>

Content-Key: 313942

Url: https://administrator.de/contentid/313942

Printed on: April 19, 2024 at 16:04 o'clock

Mitglied: 129813
Solution 129813 Aug 30, 2016 updated at 11:45:57 (UTC)
Goto Top
Hi,
use the map.setCenter(latlng:LatLng|LatLngLiteral) method after you load your layer, to re-center.
https://developers.google.com/maps/documentation/javascript/reference

Regards
Member: tingel
tingel Aug 30, 2016 updated at 12:12:59 (UTC)
Goto Top
Hi,
this does not work.
map.setCenter(new google.maps.LatLng(37.4419, -122.1419));

When i call it, the map is center at this for a very short time and then it springs to an other center (KML).

But with preserveViewport: true it works, thank you