Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Google Map API polyline question

    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!



    Code:
    <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>
    Last edited by ynotlim; 02-22-2007 at 03:10 AM.
    ---------
    Client / Server Side Programmer II

  • #2
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there,

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

    Code:
    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);
    		  }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •