How to track in google earth using c#.

2,510 views
Skip to first unread message

shahid aleem

unread,
Mar 26, 2011, 2:15:40 PM3/26/11
to KML Developer Support - Google Earth Plug-in
Hello all,

I am developing an application for online and offline vehicle
tracking.

I have got longitude and latitude values. But i dont know how to pass
these longitude and latitude to google earth plugin and track
vehicles. I want to monitor the vehicle where it is going and the
complete movements online. besides this i want to onitor complete day
movement offline. Please some body suggest me how to do this. I am
totally blank regarding this.

Hope to get respone regarding this.

Thanks in advance.

StarTraX

unread,
Mar 26, 2011, 5:16:29 PM3/26/11
to KML Developer Support - Google Earth Plug-in
You're not really giving us much to go on on here. It's all possible,
but you'll have to tell us where you're stuck to help.
Have you looked at examples from http://code.google.com/apis/earth/documentation/examples.html
to get a start?

StarTraX

unread,
Mar 26, 2011, 5:19:52 PM3/26/11
to KML Developer Support - Google Earth Plug-in
Your post title referred to C#, so you should also look at
http://earth-api-samples.googlecode.com/svn/trunk/demos/desktop-embedded/index.html


On Mar 27, 5:15 am, shahid aleem wrote:

shahid aleem

unread,
Mar 27, 2011, 12:48:05 PM3/27/11
to google-earth-...@googlegroups.com
Hello,

Today i have done some thing like this to add placemarks which i am getting from database. Here i want to add line which connects all these placemarks.....

the code is
source code


 <script src="https://www.google.com/jsapi?key=ABQIAAAAL8fYTHcAr1LaUQK8ZZoeYRQ60NUxjVrMy9o1Bj8zixztUtKLDBSJfbnbUJ_6oIA1DnYum_Y2YdVpsA"
        type="text/javascript"></script>

    <script type="text/javascript" language="javascript">

        var ge;

        var animRunning = false;
        var ANIM_ALTITUDE = 100;

        google.load("earth", "1");
        var mystr1;
        function init() {
            debugger;
            google.earth.createInstance('map3d', initCB, failureCB);
        }

        var Lat = 0.0, Longt = 0.0;

        var myItems1 = [];
        var myItems2 = [];
       
        function Latitute(val1, val2) {

            for (var i = 0; i < val1.length; i++) {
                myItems1[i] = val1[i];
            }

            for (var i = 0; i < val2.length; i++) {
                myItems2[i] = val2[i];
            }

            Lat = myItems1[0];
            Longt = myItems2[0];
        }

        function initCB(instance) {
            debugger;
            ge = instance;
            ge.getWindow().setVisibility(true);

            // add some layers
            ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
            ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
            ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

            var placemark = ge.createPlacemark('');
            placemark.setName("Alexmar Office");
            ge.getFeatures().appendChild(placemark);

            //            // Create style map for placemark
            //            var icon = ge.createIcon('');
            //            icon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
            //            var style = ge.createStyle('');
            //            style.getIconStyle().setIcon(icon);
            //            placemark.setStyleSelector(style);

            // Create point
            var point = ge.createPoint('');
            point.setLatitude(Lat);
            point.setLongitude(Longt);

            // ge.getOptions().setMouseNavigationEnabled(false);

            var camera = ge.createCamera('');
            camera.set(Lat, Longt, ANIM_ALTITUDE, ge.ALTITUDE_RELATIVE_TO_GROUND,
      15, -15, 10);
            ge.getView().setAbstractView(camera);

            placemark.setGeometry(point);

            startAnimationClick();

            // just for debugging purposes
            document.getElementById('installed-plugin-version').innerHTML =
    ge.getPluginVersion().toString();
        }

        google.setOnLoadCallback(init);


        function failureCB(errorCode) {
        }

        function startAnimationClick() {
       
                for (var i = 1; i < myItems1.length; i++) {

                    tickAnimation(myItems1[i], myItems2[i]);
                } 
        }

        var i = 0;
        function tickAnimation(val1, val2) {

            debugger;
       
            //////////////////////////////////////////////////////////// Commented for line string ///////////////
                        var placemark = ge.createPlacemark('');
            //            placemark.setName("Alexmar Office");
                        ge.getFeatures().appendChild(placemark);

                        //            // Create style map for placemark
                        //            var icon = ge.createIcon('');
                        //            icon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
                        //            var style = ge.createStyle('');
                        //            style.getIconStyle().setIcon(icon);
                        //            placemark.setStyleSelector(style);

                        // Create point
                        var point = ge.createPoint('');
                        point.setLatitude(val1);
                       point.setLongitude(val2);
            /////////////////////////////////////////////////////////////////////// End Comments Uncomment Single


            // create the line string placemark

            // an example of some camera manipulation that's possible w/ the Earth API
            var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);

            camera.setAltitude(ANIM_ALTITUDE);
            camera.setLatitude(val1);
            camera.setLongitude(val2);

            ge.getView().setAbstractView(camera);

            placemark.setGeometry(point);

            ////////////////////////////////////////////////////////////// Line String Trial

            var lineStringPlacemark = ge.createPlacemark('');

            // create the line string geometry
            var lineString = ge.createLineString('');

            // tessellate (i.e. conform to ground elevation)
            lineString.setTessellate(true);

            i = i + 5;

            lineString.getCoordinates().pushLatLngAlt(val1 + i, val2 + i, 10);
            ge.getFeatures().appendChild(lineStringPlacemark);
           
            lineStringPlacemark.setGeometry(lineString);

            ////////////////////////////////////////////////////////////////////////////  End Line String Trial
        }
       
    </script>

    <div>
        <input type="button" value="Click me!" onclick="startAnimationClick()" />
        <br />
        <div id="map3d" style="height: 600px;">
        </div>
    </div>

and this is my code behind in my page load event i am gettin latitudes and longitudes and sending it to javascript function....

CustomSQLCommand cmd = new CustomSQLCommand("select * from tbl_Locators_tracks", false);
        DataSet ds = cmd.ExecuteDataSet();

        latArray = new double[ds.Tables[0].Rows.Count];
        longArray = new double[ds.Tables[0].Rows.Count];


        if (ds.Tables[0].Rows.Count > 0)
        {
            try { LatitudeVal = double.Parse(ds.Tables[0].Rows[0]["Latitude"].ToString()); }
            catch { }
            try { LongitudeVal = double.Parse(ds.Tables[0].Rows[0]["Longitude"].ToString()); }
            catch { }

            latArrayString = "[";
            longArrayString = "[";
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                latArrayString =  latArrayString + ds.Tables[0].Rows[i]["Latitude"].ToString() + ",";
                longArrayString = longArrayString + ds.Tables[0].Rows[i]["Longitude"].ToString() + ",";
            }
            latArrayString = latArrayString.Remove(latArrayString.Length - 1, 1);
            longArrayString = longArrayString.Remove(longArrayString.Length - 1, 1);
            latArrayString = latArrayString+"]";
            longArrayString = longArrayString + "]";

        }

        ClientScriptManager cs = Page.ClientScript;
 
        cs.RegisterStartupScript(this.GetType(), "Send", "Latitute("+ latArrayString + "," + longArrayString + ");", true);



Please tell me how to create line for this placemarks when google earth load in my page... Thanks

StarTraX

unread,
Mar 27, 2011, 10:32:29 PM3/27/11
to KML Developer Support - Google Earth Plug-in
Sorry, I'm just not keen on debugging others' code ( I spend enough
time debugging my own!). What's the problem? You seem to have the
grasp of the concepts - you just need to debug it step by step.
My approach is to get a piece of code that works and then add
functionality bit-by-bit, testing each step of the way.
That way I can easily go back to the last piece that worked and debug
the bit with a problem.


On Mar 28, 3:48 am, shahid aleem wrote:
> Hello,
>
> Today i have done some thing like this to add placemarks which i am getting
> from database. Here i want to add line which connects all these
> placemarks.....
>
> the code is
> source code
>
>  <script
> src="https://www.google.com/jsapi?key=ABQIAAAAL8fYTHcAr1LaUQK8ZZoeYRQ60NUx..."

shahid aleem

unread,
Mar 28, 2011, 3:18:14 AM3/28/11
to google-earth-...@googlegroups.com
Dear,

the problem here i am facing is to create route for the placemarks, i am done with placing the markers but now i want a route on all these placemarks which connects each other and shows the route. if you know this please tell me how to do this. while debugging i am not getting any error but also i am not getting line for this. so i am not able to understand where i am wrong.

Thanks.

fraser (Earth API Guru)

unread,
Mar 28, 2011, 10:12:49 AM3/28/11
to KML Developer Support - Google Earth Plug-in
Hi,

Not sure if it is the issue, but try adding the geometry to the
placemark before you add the placemark to the plugin.

e.g.

lineStringPlacemark.setGeometry(lineString);
ge.getFeatures().appendChild(lineStringPlacemark);

F.

On Mar 27, 5:48 pm, shahid aleem wrote:
> Hello,
>
> Today i have done some thing like this to add placemarks which i am getting
> from database. Here i want to add line which connects all these
> placemarks.....
>
> the code is
> source code
>
>  <script
> src="https://www.google.com/jsapi?key=ABQIAAAAL8fYTHcAr1LaUQK8ZZoeYRQ60NUx..."

fraser (Earth API Guru)

unread,
Mar 28, 2011, 10:32:42 AM3/28/11
to KML Developer Support - Google Earth Plug-in
Also, just to note vehicle tracking is specifically prohibited in the
TOS....

http://www.google.com/help/terms_maps.html

(g) use the Service or Content with any products, systems, or
applications for or in connection with (i) real time navigation or
route guidance, including but not limited to turn-by-turn route
guidance that is synchronized to the position of a user's sensor-
enabled device...

shahid aleem

unread,
Mar 28, 2011, 12:41:37 PM3/28/11
to google-earth-...@googlegroups.com
Hello Thanks for Help,

I have used the following code for creating Line before placemark and it worked...... Thanks again..........

 new code for LineString and placemarks

 var val3 = 0.0, val4 = 0.0;
        function tickAnimation(val1, val2) {


            ////////////////////////////////////////////////////////////// Line String Trial



            if (val3 != 0.0 && val4 != 0.0) {



                var lineStringPlacemark = ge.createPlacemark('');

                // Create the LineString

                var lineString = ge.createLineString('');
                lineStringPlacemark.setGeometry(lineString);

                // Add LineString points
                lineString.getCoordinates().pushLatLngAlt(val1, val2, 0);
                lineString.getCoordinates().pushLatLngAlt(val3, val4, 0);

                lineStringPlacemark.setStyleSelector(ge.createStyle(''));
                var lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle();
                lineStyle.setWidth(10);
                lineStyle.getColor().set('ffff0000');


                ge.getFeatures().appendChild(lineStringPlacemark);

                lineStringPlacemark.setName('Line Strings');
                lineStringPlacemark.setDescription('Route');

//////////////////////////////////////////////////////////////////////////////////// Multi Line //////////////////////////////////////////////////
//                var line1 = ge.createLineString('');
//                line1.getCoordinates().pushLatLngAlt(val1, val2, 0);
//                line1.getCoordinates().pushLatLngAlt(val3, val4, 0);

//                line1.setTessellate(true);
//                line1.setAltitudeMode(ge.ALTITUDE_CLAMP_TO_GROUND);

//                var line2 = ge.createLineString('');
//                line2.getCoordinates().pushLatLngAlt(val1, val2, 0);
//                line2.getCoordinates().pushLatLngAlt(val3, val4, 0);

//                line2.setTessellate(true);
//                line2.setAltitudeMode(ge.ALTITUDE_CLAMP_TO_GROUND);

//                var multiGeometry = ge.createMultiGeometry('');
//                multiGeometry.getGeometries().appendChild(line1);
//                multiGeometry.getGeometries().appendChild(line2);

//                var multGeoPlacemark = ge.createPlacemark('');
//                multGeoPlacemark.setGeometry(multiGeometry);

//                multGeoPlacemark.setStyleSelector(ge.createStyle(''));
//                var lineStyle = multGeoPlacemark.getStyleSelector().getLineStyle();
//                lineStyle.setWidth(10);
//                lineStyle.getColor().set('ffff0000');

//                ge.getFeatures().appendChild(multGeoPlacemark);

//                multGeoPlacemark.setName('Line Strings');
//                multGeoPlacemark.setDescription('Two separate lineStrings, one description.');
//////////////////////////////////////////////////////////////////////////// End /////////////////////////////////////////////////////////////////////

            }

            ////////////////////////////////////////////////////////////////////////////  End Line String Trial


            val3 = val1; val4 = val2;

       
       
       

         
       
          
                        var placemark = ge.createPlacemark('');
         
                        ge.getFeatures().appendChild(placemark);


                    
                        // Create point
                        var point = ge.createPoint('');
                        point.setLatitude(val1);
                       point.setLongitude(val2);
        

          

        
Reply all
Reply to author
Forward
0 new messages