Hi sir,

  kml file is working fine. can any one help me how to add icons at starting
point and ending point. my php code is mentioned below.

<?php
require('phpsqlajax_dbinfo.php');

// Opens a connection to a MySQL server
$connection = mysql_connect ("localhost", $username, $password);

if (!$connection)
{
   die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);

if (!$db_selected)
{
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table

//$query = " SELECT GROUP_CONCAT(lon, ',', lat, ',', '100' separator ' ') AS
coordinates FROM markers WHERE type = 'restaurant';";
$query='SELECT * FROM route where route_id=7';
$result = mysql_query($query);
if (!$result)
{
  die('Invalid query: ' . mysql_error());
}

// Start KML file, create parent node
$dom = new DOMDocument('1.0','UTF-8');

//Create the root KML element and append it to the Document
$node = $dom->createElementNS('http://earth.google.com/kml/2.1','kml');
$parNode = $dom->appendChild($node);

 // Creates a KML Document element and append it to the KML element.
  $dnode = $dom->createElement('Document');
  $docNode = $parNode->appendChild($dnode);

//Create a name element and append it to the KML element
$fnode = $dom->createElement('name','routeplan');
//$folderNode = $parNode->appendChild($fnode);
$docNode->appendChild($fnode);
$fnode1= $dom->createElement('description', 'route plan between two selected
places');
$docNode->appendChild($fnode1);

//Iterate through the MySQL results
while($row = @mysql_fetch_assoc($result))
{
//Create Styleid
$StyleNode=$dom->createElement('Style');
$StyleNode->setAttribute('id', 'Style' . $row['route_id']);
$StyleNode1=$docNode->appendChild($StyleNode);

// line style node
$LineStyleNode1=$dom->createElement('LineStyle');
$LineStyleNode=$StyleNode1->appendChild($LineStyleNode1);
//line colour
$LineColor=$dom->createElement('color','990000ff');
$LineStyleNode->appendChild($LineColor);
//line width
$LineWidth=$dom->createElement('width','4');
$LineStyleNode->appendChild($LineWidth);
$StyleNode1->appendChild($LineStyleNode);

//Create a Placemark and append it to the document
$node = $dom->createElement('Placemark');
$placeNode = $docNode->appendChild($node);

//Create name, description, and address elements and assign them the values
of
//the name, type, and address columns from the results

$nameNode = $dom->createElement('name',$row['route_name']);
$placeNode->appendChild($nameNode);

$descNode= $dom->createElement('description', ' start_point to end_point: '
. $row['start_point'] . "  to  " . $row['end_point']);
$placeNode->appendChild($descNode);

$styleURL=$dom->createElement('StyleURL','#Style' . $row['route_id']);
$placeNode->appendChild($styleURL);

//Create a LineString element
$lineNode = $dom->createElement('LineString');
$placeNode->appendChild($lineNode);

$almodenode =$dom->createElement('altitudeMode','relative');
$lineNode->appendChild($almodenode);

 // Creates a coordinates element and gives it the value of the lng and latt
columns from the results.
     $coorStr = explode(";",$row['geo_points']);

 // for($i=0;$i<count($coorStr);$i++)
   //   {
    $coorNode = $dom->createElement('coordinates',implode(",0\n ",
$coorStr));

      $lineNode->appendChild($coorNode) ;
   //  }
  }


//$coorNode = $dom->createElement('coordinates',$row['coordinates']);
//$lineNode->appendChild($coorNode);
$kmlOutput = $dom->saveXML();

//assign the KML headers.
header('Content-type: application/vnd.google-earth.kml+xml');
echo $kmlOutput;
?>


Thanks in advance,

with sincerely,
sravan

2009/3/9 sravan kumar gudivada <gudivada...@gmail.com>

> I strucked here, please help me..i am not understanding what is the problem
> in my code.
>
> Thanks in advance,
>
> with sincerely,
> sravan
>
>
> On Mon, Mar 9, 2009 at 11:40 AM, sravan <gudivada...@gmail.com> wrote:
>
>>
>> Hi sir,
>>
>> Below i wrote the code for, adding the route data(india) into google
>> map and show those details into map.
>>
>> i wrote php script for generating kml file, its working fine when i
>> was trying with mymaps in google, but it is not working with my api
>> map.
>>
>> can any one please help to me.
>>
>> <html>
>>  <head>
>>
>>    <meta http-equiv="content-type" content="text/html; charset=utf-8"/
>> >
>>    <title>Add Route</title>
>> <script
>> src="http://maps.google.com/maps?
>>
>> file=api&amp;v=2&amp;sensor=true&amp;key=ABQIAAAAbX5c_xOgi1Oyuvze35DsJhTrC5KDP_AfmCOqbnkDTfEMEzPPWhSaDk8rp1Tj6xtmKeARnBPdq79-9w<http://maps.google.com/maps?%0Afile=api&v=2&sensor=true&key=ABQIAAAAbX5c_xOgi1Oyuvze35DsJhTrC5KDP_AfmCOqbnkDTfEMEzPPWhSaDk8rp1Tj6xtmKeARnBPdq79-9w>
>> "
>>    type="text/javascript">
>>  </script>
>>
>> <script type="text/javascript">
>>    var geostring="";
>>    var marker;
>>    var count=0;
>>    var index=0;
>>    var points=new Array();
>>    var markers=new Array();
>>    var distance=0;
>>    var report= document.getElementById("status");
>>   function initialize() {
>>      if (GBrowserIsCompatible()) {
>>        var map = new GMap2(document.getElementById("map_canvas"),
>> {draggableCursor: 'crosshair', draggingCursor: 'move'});
>>
>>        // Load initial map and a bunch of controls
>>        map.setCenter(new GLatLng(8.558513,76.88198),14);
>>        map.addControl(new GLargeMapControl()); // Zoom control
>>        map.addControl(new GMenuMapTypeControl()); // Toggle between
>> map types
>>        map.addControl(new GOverviewMapControl());//map overview
>> control
>>        map.addControl(new GScaleControl());
>>        map.enableScrollWheelZoom();
>>        map.enableDoubleClickZoom();
>>        map.enableContinuousZoom();
>>        map.addMapType(G_PHYSICAL_MAP);
>>      var geoXml = new GGeoXml('http://sites.google.com/site/
>> vehiclefleettrackingsystem/Home/r1.kml?attredirects=0'<http://sites.google.com/site/%0Avehiclefleettrackingsystem/Home/r1.kml?attredirects=0%27>
>> );
>>         map.addOverlay(geoXml);
>>
>>     GEvent.addListener(map, "click", function(overlay, latlng) {
>>          if (latlng) {
>>            count++;
>>            marker = new GMarker(latlng, {draggable:true});
>>            map.addOverlay(marker);
>>          //  marker.content=count;
>>            markers.push(marker);
>>            points.push(latlng);
>>            geostring+=latlng.x+","+latlng.y+";";
>>          if(markers.length>1){
>>             var poly=new GPolyline(points,"#000000",2,1)
>>              map.addOverlay(poly);
>>              distance =distance+(poly.getLength()/1000);
>>         //     var unit = " km";
>>         //     report.innerHTML = "Total line length:<br> " +
>> distance.toFixed(3) + unit;
>>          }
>>          }
>>
>>          });
>>
>>      }
>>    }
>>
>>    function saveData() {
>>      var start_point = escape(document.getElementById
>> ("start_point").value);
>>      var end_point = escape(document.getElementById
>> ("end_point").value);
>>      var route_name = document.getElementById("route_name").value;
>>      var geo_points = geostring;
>>
>>      var url = "addroute.php?start_point=" + start_point +
>> "&end_point=" + end_point +
>>                "&geo_points=" + geo_points + "&route_name=" +
>> route_name +"&distance="+distance;
>>      GDownloadUrl(url, function(data, responseCode) {
>>        if (responseCode == 200 && data.length <= 1) {
>>
>> //         document.getElementById("message").innerHTML = "Route
>> added.";
>>           alert("route added");
>>
>>       }
>>      });
>>    }
>>    </script>
>>
>>  </head>
>>
>>  <body onload="initialize()" onunload="GUnload()">
>>
>>      <form type="text">
>>       StartingPointName:<input type="text" id="start_point" />
>>       EndingPointName:<input type="text" id="end_point"/>
>>       RouteName:<input type="text" id="route_name">
>>       <input type='button' value='Save' onclick='saveData()'/>
>>       <!--input id="status" style="height:70px"/>&nbsp;-->
>>
>>  </form>
>>    <table border=1>
>>      <tr>
>>        <td>
>>  <div id="map_canvas" style="width: 800px; height:450px; border-width:
>> 2px;  border-style: solid; border-color: green "></div>
>>        </td>
>>        <td width = 150 valign="top" style="text-decoration:
>> underline; color: #4444ff;">
>>           <div id="side_bar"></div>
>>        </td>
>>      </tr>
>>
>>    </table>
>>
>>    <div id="message"></div>
>>  </body>
>>
>> </html>
>>
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to Google-Maps-API@googlegroups.com
To unsubscribe from this group, send email to 
google-maps-api+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to