I want to highlight a mobile trace on Google Maps and GIS data from my network must also be visible.
I am able to plot hard coded coordinates on Google Maps but not from a *.csv file.
Note: *.csv file contains Lat & Long values to highlight traced route
Hi....I am able to highlight the route now but if i enter too many coordinates then the page responses very slowly....kindly can any ony let me know the limits ....I am post my code...plz mention if i am going in wrong direction.....Thanks
<>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>MySiteMap</title>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDuSN0u2fpgle4eYZ1kxPHmTA8maKJynYE&sensor=false">
</script>
<script src="label.js">
</script>
<script>
var a_Lat=new Array();
var a_Long=new Array();
var myLatLong = new Array();
var myOtherSite = new Array();
var myTataSite = new Array();
var map;
var myCenter=new google.maps.LatLng(18.980599,75.766536);
function initialize()
{
//alert("Hello");
///sets lat_long values for polyline.
var excel = new ActiveXObject("Excel.Application");
var excel_file_r = excel.Workbooks.Open("D:\\Priyanka\\EGIS\\somefile.xls");
var excel_file_s = excel.Workbooks.Open("D:\\Priyanka\\EGIS\\sitefile.xls");
var excel_sheet_r = excel_file_r.Worksheets("sheet1");
var excel_sheet_s = excel_file_s.Worksheets("sheet1");
var data = excel_sheet_r.Cells(1,2).Value;
alert("kklk");
for (var i=2; i<10000; i++)
{
if(excel_sheet_r.Cells(i,1).Value==undefined || excel_sheet_r.Cells(i,2).Value==undefined)
{
//alert(i);
//alert(i+" "+"about to break");
break;
}
//data = excel_sheet_r.Cells(i+1,i).Value;
a_Lat[i-2]=excel_sheet_r.Cells(i,1).Value;
a_Long[i-2]=excel_sheet_r.Cells(i,2).Value;
myLatLong[i-2]=new google.maps.LatLng(a_Lat[i-2],a_Long[i-2]);
//alert(myLatLong[i-2]);
}
///sets latlong for Tata Sites
//alert("kklk");
var counter_a = 0;
for (var i=2; i<10000; i++)
{
if(excel_sheet_s.Cells(i,1).Value==undefined || excel_sheet_s.Cells(i,2).Value==undefined)
{
break;
}
else
{
myTataSite[i-2]=new google.maps.LatLng(excel_sheet_s.Cells(i,1).Value,excel_sheet_s.Cells(i,2).Value);
counter_a = counter_a + 1;
}
}
alert(counter_a);
var counter1_a = 0;
///sets latlong for ICR Sites
for (var i=2; i<10000; i++)
{
if(excel_sheet_s.Cells(i,3).Value==undefined || excel_sheet_s.Cells(i,4).Value==undefined)
{
break;
}
else
{
myOtherSite[i-2]=new google.maps.LatLng(excel_sheet_s.Cells(i,3).Value,excel_sheet_s.Cells(i,4).Value);
counter1_a = counter1_a + 1;
}
}
alert(counter1_a);
///Release Excel object.
excel.Quit();
excel = null;
alert("BYE");
///sets map properties
var mapProp = {
center:myLatLong[1],
zoom:4,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
///Map object is defined
map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
//------------------First KML file.......
var ctaLayer3 = new google.maps.KmlLayer({
url: 'https://sites.google.com/site/turbhegiskmlfiles/gis/cluster_boundry.kml'
});
//------------------second KML file......
var ctaLayer4 = new google.maps.KmlLayer({
url: 'https://sites.google.com/site/turbhegiskmlfiles/gis/WRL_Kolhpaur.kml'
});
var myTrip = new Array();
///-------------------------------------------------------------------------------------------------------///
///-----------------------------------DEFINE POLYLINE-----------------------------------------------------///
///-------------------------------------------------------------------------------------------------------///
myTrip = myLatLong;
var flightPath=new google.maps.Polyline({
path:myTrip,
strokeColor:"#FF00FF",
strokeOpacity:0.8,
strokeWeight:5
});
///Place marker on clicked location
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
addruler(event.latLng);
});
/*
var markerTata=new google.maps.Marker({
position:o_site1,
icon:'tower.png'
});
var markerOther=new google.maps.Marker({
position:t_site1,
icon:'tata.png'
});
var mySiteOther = new google.maps.Circle({
center:o_site1,
radius:2000,
strokeColor:"#CC00CC",
strokeOpacity:0.3,
strokeWeight:2,
fillColor:"#CCCCFF",
fillOpacity:0.4
});
var mySiteTata = new google.maps.Circle({
center:t_site1,
radius:75,
strokeColor:"#0099FF",
strokeOpacity:0.8,
strokeWeight:2,
fillColor:"#99FFFF",
fillOpacity:0.4
});
*/
alert("set")
var mySiteTata = new Array();
var markerTata = new Array();
var mySiteOther = new Array();
var markerOther = new Array();
var infowindow1;
///sets TATA sites
for (var i=0;i<500;i++)
{
markerTata[i]=new google.maps.Marker({
position:myTataSite[i],
icon:'tata.png'
});
mySiteTata[i] = new google.maps.Circle({
center:myTataSite[i],
radius:2000,
strokeColor:"#0099FF",
strokeOpacity:0.8,
strokeWeight:2,
fillColor:"#99FFFF",
fillOpacity:0.1
});
infowindow1 = new google.maps.InfoWindow({
content:"Tata Site"
});
google.maps.event.addListener(markerTata[i], 'mouseover', function() {
infowindow1.open(map,markerTata[i])
});
//infowindow1.open(map,markerTata[i]);
mySiteTata[i].setMap(map);
markerTata[i].setMap(map);
}
///sets ICR sites
for (var i=0;i<counter1_a;i++)
{
markerOther[i]=new google.maps.Marker({
position:myOtherSite[i],
icon:'home.png'
});
mySiteOther[i] = new google.maps.Circle({
center:myOtherSite[i],
radius:2000,
strokeColor:"#CC00CC",
strokeOpacity:0.8,
strokeWeight:2,
fillColor:"#CCCCFF",
fillOpacity:0.1
});
mySiteOther[i].setMap(map);
markerOther[i].setMap(map);
}
ctaLayer3.setMap(map);
ctaLayer4.setMap(map);
flightPath.setMap(map);
}
function placeMarker(location) {
var marker3 = new google.maps.Marker({
position: location,
map: map,
});
var infowindow3 = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow3.open(map,marker3);
}
//####################################################################
/*
javascript ruler for google maps V3
by Giulio Pons. http://www.barattalo.it
this function uses the label class from Marc Ridley Blog
*/
function addruler(location) {
var ruler1 = new google.maps.Marker({
position: location ,
map: map,
draggable: true
});
var ruler2 = new google.maps.Marker({
position: location ,
map: map,
draggable: true
});
//alert(ruler1.getPosition());
var ruler1label = new Label({ map: map });
var ruler2label = new Label({ map: map });
//alert("hjj");
ruler1label.bindTo('position', ruler1, 'position');
ruler2label.bindTo('position', ruler2, 'position');
var rulerpoly = new google.maps.Polyline({
path: [ruler1.position, ruler2.position] ,
strokeColor: "#FFFF00",
strokeOpacity: .7,
strokeWeight: 4
});
rulerpoly.setMap(map);
ruler1label.set('text',distance( ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
ruler2label.set('text',distance( ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
google.maps.event.addListener(ruler1, 'drag', function() {
rulerpoly.setPath([ruler1.getPosition(), ruler2.getPosition()]);
ruler1label.set('text',distance( ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
ruler2label.set('text',distance( ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
});
google.maps.event.addListener(ruler2, 'drag', function() {
rulerpoly.setPath([ruler1.getPosition(), ruler2.getPosition()]);
ruler1label.set('text',distance( ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
ruler2label.set('text',distance( ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
});
}
function distance(lat1,lon1,lat2,lon2) {
var R = 6371; // km (change this constant to get miles)
var dLat = (lat2-lat1) * Math.PI / 180;
var dLon = (lon2-lon1) * Math.PI / 180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
if (d>1) return Math.round(d)+"km";
else if (d<=1) return Math.round(d*1000)+"m";
return d;
}
function all_clear(){
alert("Here")
map.setMap(null);
}
//####################################################################
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<p style="font-family:arial;color:magenta;font-size:20px;"> This is My web Page </p><br><br>
<br><br><br>
<div id="googleMap" style="width:500px;height:580px;"></div> <br><br><br><br>
<p>Data in Excel is : **3652 https://sites.google.com/site/turbhegiskmlfiles/gis/shirur_to_ahmednagar.kml **</p>
<p id = "demo"> Data is as follows: </p>
</body>
</html>
<>