Yahoo! Maps

  • Onderwerp starter Onderwerp starter bn2vs
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

bn2vs

Terugkerende gebruiker
Lid geworden
18 aug 2007
Berichten
1.705
Ik heb de volgende JS code:

Code:
<script type='text/javascript' src='http://api.maps.yahoo.com/ajaxymap?v=3.8&amp;appid=YD-eQRpTl0_JX2E95l_xAFs5UwZUlNQhhn7lj1H'></script>
			<script type='text/javascript'>	
			function createYMarker(geoPoint, title, label){
			var newMarker= new YMarker(geoPoint);
			var markerMarkup = label;
			YEvent.Capture(newMarker, EventsList.MouseClick, 
				function(){
					newMarker.openSmartWindow(markerMarkup);
				});
			return newMarker;
		}</script>

...

<script type='text/javascript'>/*<![CDATA[*/
		var yahoo_location_1 = new YGeoPoint(-33.867139, 151.207114); // Create the location with lat and long
		var yahoo_1 = new YMap(document.getElementById('map-yahoo-1')); // Create a map object 
		yahoo_1.addTypeControl(); // Add map type control  
		yahoo_1.addZoomLong(); // Add map zoom (long) control   
		yahoo_1.addPanControl(); // Add the Pan Control   
		yahoo_1.setMapType(YAHOO_MAP_HYB); // Set map type 
		 var ymap_locations_1 = Array();
						yahoo_1.addOverlay(createYMarker(new YGeoPoint(26.244813043905, 4.1074222326279), 'Location 1', ' <a href="/zend/smw/wiki/Location_1" title="Location 1">Location 1</a><br />'));
						ymap_locations_1.push(new YGeoPoint(26.244813043905, 4.1074222326279));
						yahoo_1.addOverlay(createYMarker(new YGeoPoint(51.280246, 4.0543228), 'Location 2', ' <a href="/zend/smw/wiki/Location_2" title="Location 2">Location 2</a><br />'));
						ymap_locations_1.push(new YGeoPoint(51.280246, 4.0543228));
						yahoo_1.addOverlay(createYMarker(new YGeoPoint(40.756054, -73.986951), 'Location 3', ' <a href="/zend/smw/wiki/Location_3" title="Location 3">Location 3</a><br />'));
						ymap_locations_1.push(new YGeoPoint(40.756054, -73.986951));
						yahoo_1.addOverlay(createYMarker(new YGeoPoint(-33.867139, 151.207114), 'Location 4', ' <a href="/zend/smw/wiki/Location_4" title="Location 4">Location 4</a><br />'));
						ymap_locations_1.push(new YGeoPoint(-33.867139, 151.207114));
var centerAndZoom = yahoo_1.getBestZoomAndCenter(ymap_locations_1); 
				yahoo_1.drawZoomAndCenter(centerAndZoom.YGeoPoint, centerAndZoom.zoomLevel);
		yahoo_1.drawZoomAndCenter(yahoo_location_1, 14); // Display the map centered on a geocoded location 
		/*]]>*/</script>

Wat deze code doet is een aantal markers op een Yahoo Map zetten. Wat deze ook zou moeten doen (maar niet correct doet), is de zoom and center van de map aanpassen zodat alle markers zichtbaar zijn. De laatste 2 lijnen code zijn hiervoor verantwoordelijk.

Ik krijch geen enkele error, maar de map centert gewoon op de laatste coordinaat, en de zoom is ook verkeerd.

Ik heb deze code gemaakt adhv de yahoo maps docs @ http://developer.yahoo.com/maps/ajax/V3.8/index.html
en dit voorbeeld (relevante code onderaan) http://www.assembla.com/wiki/show/jda/SimpleYahooMapInfotron

Iemand een idee wat er verkeerd gaat en hoe dit opgelost kan worden? :)

Cheers
BN
 
Ik heb hier verder nooit mee gewerkt, dus correct me if i'm wrong, maar moet je niet gewoon deze regel:

PHP:
yahoo_1.drawZoomAndCenter(yahoo_location_1, 14); // Display the map centered on a geocoded location

weghalen?

Deze zet volgens mij het zoomlevel gewoon weer op 14 (hardcoded) en voor de locatie gebruikt ie -33.867139, 151.207114.

De regel daarboven lijkt mij wel de kaart op een automatische locatie en zoomlevel te zetten.
 
:shocked: Dat was een debug line die nog ergens in mn php code stond - in de js niet gemerkt dat die er eigenlijk niet moest staan :rolleyes:

Thnx kerel, probleem opgelost :D

Puur ter demonstratie, dit is de huidige code:

Code:
<script type='text/javascript'>/*<![CDATA[*/
		var yahoo_locations_1 = new YGeoPoint(41.075658863637, -73.527740472928); // Create the location with lat and long
		var yahoo_1 = new YMap(document.getElementById('map-yahoo-1')); // Create a map object 
		yahoo_1.addTypeControl(); // Add map type control  
		yahoo_1.addZoomLong(); // Add map zoom (long) control   
		yahoo_1.addPanControl(); // Add the Pan Control   
		yahoo_1.setMapType(YAHOO_MAP_HYB); // Set map type 
		 var ymap_locations_1 = Array();
						yahoo_1.addOverlay(createYMarker(new YGeoPoint(26.244813043905, 4.1074222326279), 'Location 1', ' <a href="/zend/smw/wiki/Location_1" title="Location 1">Location 1</a><br />'));
						ymap_locations_1.push(new YGeoPoint(26.244813043905, 4.1074222326279));
						yahoo_1.addOverlay(createYMarker(new YGeoPoint(51.280246, 4.0543228), 'Location 2', ' <a href="/zend/smw/wiki/Location_2" title="Location 2">Location 2</a><br />'));
						ymap_locations_1.push(new YGeoPoint(51.280246, 4.0543228));
						yahoo_1.addOverlay(createYMarker(new YGeoPoint(41.075658863637, -73.527740472928), 'Location 3', ' <a href="/zend/smw/wiki/Location_3" title="Location 3">Location 3</a><br />'));
						ymap_locations_1.push(new YGeoPoint(41.075658863637, -73.527740472928));var centerAndZoom = yahoo_1.getBestZoomAndCenter(ymap_locations_1); 
				yahoo_1.drawZoomAndCenter(centerAndZoom.YGeoPoint, centerAndZoom.zoomLevel); 
		/*]]>*/</script>
 
Hehe, dat kan vrij lastig zijn ja ;) Mooi dat het werkt nu!
 
Heb er al met een paar andere mensen naar zitten staren, maar niemand vond iets xD

We begonnen al te denken dat er gwn iets niet pluis was met de Yahoo! Maps API ofzo :p
 
Status
Niet open voor verdere reacties.

Nieuwste berichten

Terug
Bovenaan Onderaan