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