...

View Full Version : Google Map API polyline question



ynotlim
02-22-2007, 03:06 AM
In the following google map api javascript. The polyline doesn't work in the function addAddressToMap. Here is the code that doesn't work:

point_line.push(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]));

Thanks in advance!





<script type="text/javascript">
//<![CDATA[

var map = new GMap(document.getElementById("map"));
var geocoder;
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(0, 0), 16);
geocoder = new GClientGeocoder();

// Create our "tiny" marker icon
var icon = new GIcon();
var point_line = [];
icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);

// Creates a marker whose info window displays the given number
function createMarker(point, number)
{
var marker = new GMarker(point, icon);
// Show this markers index in the info window when it is clicked
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
};

function addAddressToMap(response) {
if (!response || response.Status.code != 200) {
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
point_line.push(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]));
marker = createMarker(point, place.address + '<br>' + '<b>Country code</b>' + place.AddressDetails.Country.CountryNameCode);
map.addOverlay(marker);
point_line.push(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]));
}
}

var point = new GPoint(-123.111420,49.250776);
var marker = createMarker(point, '<div id="infowindow" style="white-space: nowrap;">Canada</div>');
map.addOverlay(marker);
point_line.push(new GLatLng(49.250776,-123.111420));

var address = 'Luneburg,Germany'
geocoder.getLocations(address, addAddressToMap)

var point = new GPoint(114.130096,22.530317);
var marker = createMarker(point, '<div id="infowindow" style="white-space: nowrap;">China</div>');
map.addOverlay(marker);
point_line.push(new GLatLng(22.530317,114.130096));

// Add a polyline with five random points.
map.addOverlay(new GPolyline(point_line));
//]]>
</script>

123gotoandplay
03-06-2007, 04:01 PM
Hi there,

Did you manage to create a poly line??? I am having the same problem



var points = [];
var point_line = [];
GEvent.addListener(map, "click", function(marker, point) {
if (marker) {
map.removeOverlay(marker);
} else {

map.addOverlay(new GMarker(point));
points.push(new GLatLng(point.x,point.y));
for(var i=0;i<points.length;i++) {
// alert("Test"+points[i]);
point_line.push(new GLatLng(points[i]));
}
polyline = new GPolyline(point_line,"#ff0000", 5, 0.7);
map.addOverlay(polyline);
alert("Test"+points);
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum