ArticleTrader.com
  

 Main Menu

  Home
  Member Login
  Forum
  Submit Article
  Membership
  RSS Feeds
  Contact Us
  About

 Services

  Article Distribution
  Link Building

 Tools

  ArticleMS
  Directory Tracker

 Categories

  Automotive
  Business
  Computers
  » Games
  » Hardware
  » Software
  Entertainment
  Finance
  Food
  Health
  Home and Family
  Internet
  Legal
  Science
  Self Improvement
  Shopping
  Society
  Sports
  Technology
  Travel
  Writing

187 users online.



 
  » Category Sponsors
  Get Your Link Here - Limited Time Bargain at only $11/month!

Home » Computers » Software » Plot Path utilising Google Map JavaScript API Part 1

sidu2410
Article written by sidu2410

View Full Profile
Get Html Code
PDF | Print View | Post to your Site

Plot Path utilising Google Map JavaScript API Part 1

Submitted by sidu2410
Mon, 30 May 2011

This item recounts how to contrive route on Google chart utilising array of latitude & longitude points.
Top of Form
Introduction
I was looking for some cipher which drags Google co-ordinates (latitude & longitude) from database and contrive the respective route on my Google map. So I revised the Google Map JavaScript API and applied a function which reads the GPS co-ordinates from a ASP.NET Data Table and plots the route on page_load event.
Background
You may mention to this item for rudimentary data about each function in Google Map JavaScript API.
Using the Code
I was adept to contrive the route between just two co-ordinates effortlessly, utilising one of Google JavaScript API function. There are numerous articles on CodeProject which provided me a good comprehending of how the Google Map JavaScript API works. However, there was no item I discovered which drags sequence of co-ordinates from a database or datatable and plots a relentless route on the run. I have clarified in steps how to manage the identical as below:
Step - 1
Create a Default.aspx sheet with the next content:
Collapse


Plot Path Demo Using Google Map JavaScript API v3


Let me interpret in short how the Google Map JavaScript API works in here. First, we add Google API JavaScript Reference in head tag:
Collapse

Then, you location a impede grade component like div on the sheet, where you desire the map to be shown:
Collapse

Next, add a JavaScript function on onload event of html body tag as below:
Collapse

Step - 2
Create a class GPSLib.cs Under App_Code book or directions & conceive the next function. I have announced the function and respective class (GPSLib) as static so it can be accessed exactly without conceiving any object.
Collapse
public static String PlotGPSPoints(DataTable tblPoints)
{
try
{
String Locations = "";
String sJScript = "";
int i = 0;
foreach (DataRow r in tblPoints.Rows)
{
// bypass empty lines
if (r["latitude"].ToString().Trim().Length == 0)
continue;

string Latitude = r["latitude"].ToString();
string Longitude = r["longitude"].ToString();

// conceive a line of JavaScript for marker on map for this record
Locations += Environment.NewLine + @"
path.push(new google.maps.LatLng(" + Latitude + ", " + Longitude + @"));

var marker" + i.ToString() + @" = new google.maps.Marker({
position: new google.maps.LatLng
(" + Latitude + ", " + Longitude + @"),
title: '#' + path.getLength(),
map: map
});";
i++;
}

// assemble the last script
sJScript = @"

var poly;
var map;

function initialize() {
var cmloc = new google.maps.LatLng
(33.779005, -118.178985);
var myOptions = {
zoom: 11,
center: cmloc,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

map = new google.maps.Map
(document.getElementById('map_canvas'), myOptions);

var polyOptions = {
strokeColor: 'blue',
strokeOpacity: 0.5,
strokeWeight: 3
}
poly = new google.maps.Polyline(polyOptions);
poly.setMap(map);

var route = poly.getPath();

" + Locations + @"
}
";
return sJScript;
}
catch (Exception ex)
{
throw ex;
}
}

 



Source: ArticleTrader.com
Creative Commons License

Comments

No comments posted.

Add Comment

You do not have permission to comment. If you log in, you may be able to comment.

 Top Authors

 1 Stebee (3270)
 2 limalan88 (2920)
 3 alien82 (2756)
 4 kajuba (2508)
 5 sverdlow (1712)
 6 jamiehanson (1705)
 7 juliet (1691)
 8 MarkeD (1296)
 9 robertoms2003 (1296)
 10 AnthonyF (1244)
 11 articles (1205)
 12 artavia.seo (1148)
 13 spinxwebdesign (1119)
 14 gprather (1071)
 15 LouieLiu (1069)

 Distribution

Article Distribution

  
  Affiliate Program 2Checkout.com, Inc. is an authorized retailer of ArticleTrader.com

0.03s