<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dijexi.com &#187; nokia</title>
	<atom:link href="http://www.dijexi.com/tag/nokia/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dijexi.com</link>
	<description>free programming tutorial, tips and tricks on php, codeigniter, delphi, dotnet, ajax and more..</description>
	<lastBuildDate>Fri, 13 Jan 2012 23:21:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>GPS Tracking Monitoring Application with Google Map</title>
		<link>http://www.dijexi.com/2009/07/gps-tracking-monitoring-application-with-google-map/</link>
		<comments>http://www.dijexi.com/2009/07/gps-tracking-monitoring-application-with-google-map/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 07:21:59 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[Google Map]]></category>
		<category><![CDATA[GPS Tracking System]]></category>
		<category><![CDATA[gps tracking]]></category>
		<category><![CDATA[n95]]></category>
		<category><![CDATA[nokia]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/07/gps-tracking-monitoring-application-with-google-map/</guid>
		<description><![CDATA[In the previous article we have discussed the global architecture of the GPS Tracking system which consists of the Tracking Device and Monitoring Application. In this article we will discuss about the GPS Tracking Application Monitoring. Introduction The monitoring application will display a Marker on the map view provided by Google Map. This Marker represents [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>In the previous article we have discussed the global architecture of the GPS Tracking system which consists of the Tracking Device and Monitoring Application. In this article we will discuss about the GPS Tracking Application Monitoring.</p>
<p> <span id="more-643"></span>
</p>
<h2>Introduction</h2>
<p>The monitoring application will display a Marker on the map view provided by Google Map. This Marker represents the last position of the GPS Tracking Device. Marker coordinate data is taken from a table on a database which contains last GPS position data and is constantly updated by the GPS Tracking Device so that the information obtained is always the up to date position.</p>
<p>The monitoring application consists of several parts that can be described as follows.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/clip_image0021.gif"><img title="Arsitektur Aplikasi Pemantau" border="0" alt="Arsitektur Aplikasi Pemantau" src="http://www.dijexi.com/wp-content/uploads/2009/07/clip_image002_thumb1.gif" width="520" height="312" /></a></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="204"><strong>Section </strong></td>
<td valign="top" width="295"><strong>Description </strong></td>
</tr>
<tr>
<td valign="top" width="204"><strong>File viewer.php</strong><strong> File viewer.php </strong></td>
<td valign="top" width="295">This is the main file of the monitoring application. This file consists of the Google Map Object. There is a definition of the timer that will call the lastpos.xml.php file periodically. On each periodic time, the display on the Google Map Marker Object will be updated with the latest position data in the database</td>
</tr>
<tr>
<td valign="top" width="204"><strong>File lastpos.xml.php</strong><strong> File lastpos.xml.php </strong></td>
<td valign="top" width="295">This file is used to read data from the database and generate output data in the form of XML to be used by a Google Map to display the Object Marker on a certain position.</td>
</tr>
<tr>
<td valign="top" width="204"><strong>Google Map Object</strong><strong> Google Map Object </strong></td>
<td valign="top" width="356">Google Map object that is used for displaying a map on a coordinate position and a zoom level.</td>
</tr>
</tbody>
</table>
<p>Next let us study in detail the functional part of each Monitoring Application.</p>
<h2>User Interface Design</h2>
<p>Here is a display of user interface design for the monitoring application that we are going to build.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/clip_image0042.gif"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://www.dijexi.com/wp-content/uploads/2009/07/clip_image0024.gif" width="240" height="191" /></a></p>
<p>The user interface is very simple, consisting only of the Google Map object, the list box that contains the code of the moving objects that will be observed, and one button to zoom the map that will move the position of Google Map with a center point, that is the coordinates of the selected objects selected in the list box. Besides that, we will also see the information box that contains the detail information about the selected moving objects such as code, coordinates, time, and so forth.</p>
<h2>Google Map Object initialization</h2>
<p>Note the program source code below, which is a fragment of the file <strong>viewer.php.</strong></p>
<div class="dean_ch" style="white-space: wrap;">&lt;!DOCTYPE html <span class="kw2">PUBLIC</span> <span class="st0">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span> <span class="st0">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;</span>&gt;&lt;html xmlns=<span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=<span class="st0">&quot;content-type&quot;</span> content=<span class="st0">&quot;text/html; charset=utf-8&quot;</span>/&gt;<br />
&lt;title&gt;Sistem Pemantau GPS Tracking&lt;/title&gt;<br />
&lt;script src=<span class="st0">&quot;http://maps.google.com/maps?file=api&amp;amp;amp;v=2&amp;amp;amp;key=abcde&quot;</span> type=<span class="st0">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;<br />
&lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt;<br />
<span class="co1">//&lt;![CDATA[</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> map = <span class="kw2">null</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> timeOut=<span class="kw2">null</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> markers=<span class="br0">&#91;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp;<span class="kw2">var</span> htmls=<span class="br0">&#91;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp;<span class="kw2">function</span> load<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>GBrowserIsCompatible<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; map = <span class="kw2">new</span> GMap2<span class="br0">&#40;</span>document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&quot;map&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; map.<span class="me1">setCenter</span><span class="br0">&#40;</span><span class="kw2">new</span> GLatLng<span class="br0">&#40;</span><span class="nu0">-6.8790</span>, <span class="nu0">107.63520</span><span class="br0">&#41;</span>, <span class="nu0">12</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; map.<span class="me1">enableScrollWheelZoom</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; map.<span class="me1">addControl</span><span class="br0">&#40;</span><span class="kw2">new</span> GSmallMapControl<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; map.<span class="me1">addControl</span><span class="br0">&#40;</span><span class="kw2">new</span> GMapTypeControl<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; refreshMarkers<span class="br0">&#40;</span><span class="br0">&#41;</span>;<span class="br0">&#125;</span><br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="co1">//]]&gt;</span><br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body <span class="kw3">onload</span>=<span class="st0">&quot;load()&quot;</span> <span class="kw3">onunload</span>=<span class="st0">&quot;GUnload()&quot;</span>&gt;&lt;div id=<span class="st0">&quot;map&quot;</span> style=<span class="st0">&quot;width: 400px; height: 400px&quot;</span>&gt;Loading&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div>
<p align="left">
<div style="padding-right: 20px; float: left"><iframe style="border-bottom: medium none; border-left: medium none; border-top: medium none; border-right: medium none" height="600" marginheight="0" border="0" src="http://rcm.amazon.com/e/cm?t=vitrainingcom-20&amp;o=1&amp;p=14&amp;l=st1&amp;mode=books&amp;search=google%20map&amp;fc1=000000&amp;lt1=&amp;lc1=3366FF&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" width="160" marginwidth="0" scrolling="no"></iframe></div>
<p><!-- Adsense End --></p>
<p>On the line 10-13 variable initialization is done:</p>
<ol>
<li>map : the Google Map object variables </li>
<li>timeOut: timer variable </li>
<li>markers : an array that holds all the Marker on the map </li>
<li>htmls : an array that holds all the HTML data for the information box of all existing Marker on the map </li>
</ol>
<p>On the line 15-28 defined load () function, which is first called when the HTML document is downloaded by the user. The following is done here:</p>
<ol>
<li>at line 19: make a Google Map object and store it in the variable map </li>
<li>at line 20: make the map object reacts to a button on the mouse wheel, that is if the button on the mouse wheel will cause the map to play in the zoom in and out. This is done by calling enableScrollWheelZoom() method </li>
<li>at line 21: added a map of the area control can be used to replace, men-in and zoom out the map. This is done by calling addControl () method with the parameter object GSmallMapControl. </li>
<li>On line 22: added a control area that can be used to select the type of map if the road map, satellite images, or both. This is done by calling addControl() method with the parameter object GMapTypeControl. </li>
<li>at line 23: we make a determination of the center map setCenter() method and select the type of map of the combined map and satellite map of the road (hybrid) with the method setMapType(). </li>
<li>after the initialization is done, we call the function refreshMarkers() to display the Marker which is the correct representation of the moving objects that we want to monitor. </li>
</ol>
<h2>Displaying Marker from database</h2>
<p>This is done by two functions: refreshMarkers() and createMarker(). Note the source code below, which also is part of the file <strong>viewer.php.</strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> refreshMarkers<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;clearTimeout<span class="br0">&#40;</span>timeOut<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;GDownloadUrl<span class="br0">&#40;</span><span class="st0">&quot;lastpos.xml.php&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>data, responseCode<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> fetch=<span class="nu0">0</span>;<br />
&nbsp; &nbsp; window.<span class="kw3">status</span>= responseCode + <span class="st0">&#8216;:&#8217;</span> + fetch++;<br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>responseCode != <span class="nu0">200</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="kw1">return</span>;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;markers.<span class="me1">length</span>; i++<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; map.<span class="me1">removeOverlay</span><span class="br0">&#40;</span>markers<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> xml = GXml.<span class="me1">parse</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw2">var</span> xmarkers = xml.<span class="me1">documentElement</span>.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">&quot;marker&quot;</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i = <span class="nu0">0</span>; i &lt; xmarkers.<span class="me1">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">var</span> label = xmarkers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;label&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">var</span> point = <span class="kw2">new</span> &nbsp;GLatLng<span class="br0">&#40;</span>parseFloat<span class="br0">&#40;</span>xmarkers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;lat&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>, parseFloat<span class="br0">&#40;</span>xmarkers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;lon&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp;map.<span class="me1">addOverlay</span><span class="br0">&#40;</span>createMarker<span class="br0">&#40;</span>point, i, label<span class="br0">&#41;</span> <span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
timeOut=setTimeout<span class="br0">&#40;</span><span class="st0">&quot;refreshMarkers()&quot;</span>,<span class="nu0">5000</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>The above source code displays refreshMarkers() function that will be called by the load() function as noted before.</p>
<p>The first thing that will be done each time the function is called is to turn off the timer if it’s already defined on timeOut variable. Look at line 3.</p>
<p>Next on line 5 the function GDownloadUrl() is called. The invoked URL is the <strong>lastpos.xml.php</strong> file that is the file which will output a data in the form of XML that contains coordinates information for the markers which represents the moving object to be observed. This is a simple example of the lastpos.xml.php:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?</span><br />
<a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="st0">&quot;localhost&quot;</span>,<span class="st0">&quot;root&quot;</span>,<span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="st0">&quot;dijexi_gps&quot;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$sql</span>=<span class="st0">&quot;select * from lastpos order by id&quot;</span>;<br />
<span class="re0">$res</span>=<a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$sql</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#8217;</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;&lt;markers&gt;<span class="es0">\n</span>&quot;</span>;<br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$row</span>=<a href="http://www.php.net/mysql_fetch_array"><span class="kw3">mysql_fetch_array</span></a><span class="br0">&#40;</span><span class="re0">$res</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp;<span class="re0">$unit_id</span> =<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;unit_id&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp;<span class="re0">$latitude</span> =<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;lat&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp;<span class="re0">$longitude</span> &nbsp;=<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;lon&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp;<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;marker lat=&quot;&#8217;</span>.<span class="re0">$latitude</span>.<span class="st0">&#8216;&quot; lon=&quot;&#8217;</span>.<span class="re0">$longitude</span>.<span class="st0">&#8216;&quot; label=&quot;&#8217;</span>.<span class="re0">$unit_id</span>.<span class="st0">&#8216;&quot; /&gt; &#8216;</span>;<br />
<span class="br0">&#125;</span><br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;&lt;/markers&gt;<span class="es0">\n</span>&quot;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>After downloading the data, this function will execute a function defined at it’s second parameter by giving it’s input parameter as the data obtained from the download and the responseCode (from the server).</p>
<p>This function the handle the data downloaded as shown from the line 6. First, it will show an information on the status bar about the response code to make it easy for debugging, especially if the download process from the URL was failed, which is the responseCode was not 200.</p>
<p>If the download was failed, the program is simply exits and wait for the next timer event, as seen on the line 7-10.</p>
<p>At line 12-15 we destroy all existing markers stored on the array variable markers. This is done by invoking removeOverlays() method of the map object for the markers with index i, where i begins from 0 until the size of the array element ot markers, the markers.length.</p>
<p>At line 17 we do the parsing of the XML data resulted from the download into a variable of type XML data called xml, which is done by parse() mehtod of the Gxml object.</p>
<p>After successfully parsed, the data in the object variable xml can be read to get any data element on it. For example at line 18, we read the element named “marker”, which is done by invoking getElementsByTagName(”marker”) method of the documentElement object contained in the xml object. The data element of the XML is then stored on JavaScript array variable called xmarkers.</p>
<p>After successfully read the element then we can do a looping through all xmarkers array elements to get the attributes of the XML. This is done at line 19 – 25, which are setting up a variable i that begins from 0 until the size of array xmarkers, that is xmarkers.length.</p>
<p>At every loop, we read the attribute “label” that exists on every XML element data. We do this by calling getAttribute(”label”) method on xmarkers object with index i. This Attribute is then stored on variable called “label”.</p>
<p>Next, at line 21-23 we also get the “lat” and “lon” attribute from every XML element data . But this time, the attribute is to be converted from string into float with the parseFloat() function, and is used as a parameter for creating a new object with type of GLatLng() and stored on a variable “point”.</p>
<p>At line 24, the “point” variable is used as a parameter for createMarker() function which is to be explained later. The Function createMarker() results a data with GMarker type which can be used to display a marker on the Google Map by calling addOverlay() method.</p>
<p>At line 28 we can see:</p>
<div class="dean_ch" style="white-space: wrap;">TimeOut = setTimeout<span class="br0">&#40;</span><span class="st0">&quot;refreshMarkers()&quot;</span>,<span class="nu0">5000</span><span class="br0">&#41;</span>;</div>
<p>This is a JavaScript command that define a timer which will execute the function refreshMarkers() every period of time, i.e 5000 ms.</p>
<p>The command itself is executed inside the body of refreshMarkers() function that will cause an infinite loop of timer events.</p>
<p>Next, this is the complete definition of createMarker() function which will be used to create a new object with type of GMarker and a parameter.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> createMarker<span class="br0">&#40;</span>point, index, label<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span> <br />
<span class="kw2">var</span> marker = <span class="kw2">new</span> GMarker<span class="br0">&#40;</span>point <span class="br0">&#41;</span>; <br />
<span class="kw2">var</span> html= <span class="st0">&quot;&lt;pre&gt;&quot;</span>+label+<span class="st0">&quot;&lt;/pre&gt;&quot;</span>;<br />
GEvent.<span class="me1">addListener</span><span class="br0">&#40;</span>marker, <span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
marker.<span class="me1">openInfoWindowHtml</span><span class="br0">&#40;</span>html<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
markers<span class="br0">&#91;</span>index<span class="br0">&#93;</span>=marker;<br />
htmls<span class="br0">&#91;</span>index<span class="br0">&#93;</span>=html;<br />
<span class="kw1">return</span> marker;<br />
<span class="br0">&#125;</span></div>
<p>The createMarker() function will be called by refreshMarkers() function as described before. This function can then be modified to result an object marker with a custom icon and not a standard icon from Google Map.</p>
<p>At line 1 is the definition of createMarker() function that have point parameter that represents the coordinate information on where the marker will be plotted on the map, an index that represents the index of the marker, and a label that will be displayed on the information box for that marker.</p>
<p>At line 2 we create a variable marker of type GMarker() object at the coordinate defined by point variable.</p>
<p>At line 3 we define a variable html that contains “&lt;pre&gt;” and the label variable taken from the function parameter and end it with “&lt;/pre&gt;”.</p>
<p>At line 4 we register a new event with the help of Gevent.addListener for the marker object on “click” event. What will be done when the object marker receive a mouse click is to invoke the function that contains the command marker.openInfoWindowHtml(). This will result: when the marker is clicked then an information box will appear with the marker information on it.</p>
<p>At line 5-6 we store the new marker on the JavaScript array markers[] and the labels for the informatin box on the JavaScript array htmls[]. Both variable will be used when the user interface need to select one of the markers exists on the Google Map.</p>
<p>At line 13 the function returns the result which is the object marker with type of GMarker recently created before.</p>
<h2>List of Objects monitored</h2>
<p>As on the specification, we need a list box that lists the moving objects to be monitored. We can choose one object from the list and click Zoom To to display the object on the map by moving Google Map to the object’s coordinate.</p>
<p>Below is the source code to creating the list box which read the data from lastpos table.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;div id=<span class="st0">&quot;controller&quot;</span> style=<span class="st0">&quot;position:absolute; left:400px; top:10px&quot;</span>&gt;<br />
&lt;form&gt; &lt;select <span class="kw3">name</span>=<span class="st0">&quot;unit_id&quot;</span> multiple&gt; &nbsp;&lt;?<br />
&nbsp; &nbsp; mysql_connect<span class="br0">&#40;</span><span class="st0">&quot;localhost&quot;</span>,<span class="st0">&quot;root&quot;</span>,<span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>;<br />
mysql_select_db<span class="br0">&#40;</span><span class="st0">&quot;dijexi_gps&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp;$sql=<span class="st0">&quot;select concat(unit_id,&#8217;|',lat,&#8217;|',lon), unit_id from lastpos order by id asc&quot;</span>;<br />
$rs = mysql_query<span class="br0">&#40;</span>$sql<span class="br0">&#41;</span> or die<span class="br0">&#40;</span>mysql_error<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">while</span> <span class="br0">&#40;</span>$row=mysql_fetch_row<span class="br0">&#40;</span>$rs<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
echo <span class="st0">&quot;&lt;option value =&#8217;&quot;</span> . $row<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> . <span class="st0">&quot;&#8217;&gt;&quot;</span> . $row<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span><br />
?&gt;<br />
&lt;/select&gt;<br />
&lt;p&gt;<br />
&lt;input type=<span class="st0">&quot;button&quot;</span> value=<span class="st0">&quot;Zoom To&quot;</span> onClick=<span class="st0">&quot;zoomTo(this.form.unit_id.selectedIndex ,this.form.unit_id.value)&quot;</span>&gt;<br />
&lt;/form&gt;<br />
&lt;/div&gt;</div>
<p>Note on the PHP code to read the data and display them into a list box. At line 5 we define an SQL command to be sent to MySQL to result a data that consists of 2 fields:</p>
<ol>
<li>the one that contained the concatenation of field unit_id, lat, and lon separated by pipe character “|”, which in here we use MySQL function CONCAT(). This field will be used as an identification of the item to be selected from list box as the “value” for that list box </li>
<li>field unit_id, to be used as the label for the list box </li>
</ol>
<p>At line 7-11 there are a PHP commands to generated all query result from the SQL command to create a HTML syntax to display a list box as specified.</p>
<p>At line 15-17 there are HTML syntax to display a “Zoom To” button that will execute JavaScript zoomTo() function when clicked, with a parameter index of the item chosen from the list box, and the value of that item. The value of that item is the concatenation of unit_id, lat, and lon separated by pipe character “|”.</p>
<p>Below is the zoomTo() function needed above:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> myclick<span class="br0">&#40;</span>i<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
markers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">openInfoWindowHtml</span><span class="br0">&#40;</span>htmls<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span> </p>
<p><span class="kw2">function</span> zoomTo<span class="br0">&#40;</span>index, unit_id<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>unit_id==<span class="st0">&quot;&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&#8216;Please select Unit ID&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp;<span class="kw1">return</span> ;<br />
<span class="br0">&#125;</span><br />
<span class="kw2">var</span> temp = <span class="kw2">new</span> Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
temp = unit_id.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&#8216;|&#8217;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> p=<span class="kw2">new</span> GLatLng<span class="br0">&#40;</span>parseFloat<span class="br0">&#40;</span>temp<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>, parseFloat<span class="br0">&#40;</span>temp<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;map.<span class="me1">setCenter</span><span class="br0">&#40;</span>p,<span class="nu0">13</span><span class="br0">&#41;</span>;<br />
myclick<span class="br0">&#40;</span>index<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>Note at line 5, we define the zoomTo() function. The function is to be called when the “Zoom To” button is clicked that will make Google Map to have a center point to be the same as the coordinate of the object selected from the list box and the do the zoom at a certain level.</p>
<p>At line 7-10 we do the checking of whether the parameter variable unit_id is not empty, which means that whether a user has chosen one of the item from the list box before. If not, then just exits from the function.</p>
<p>At line 12-13 we define an array variable temp to store the data from the separation of the variable unit_id with pipe character “|”. The results are the temp variable which has 3 element: unit_id, latitude, and longitude.</p>
<p>At line 14, we create an object variable p of type GLatLng() with parameter temp[1] and temp[2] which are lat and lon defined and converted info float by parseFloat() function before.</p>
<p>At line 15 we set the center point for Google Map to be the coordinate of the p variable which is the same as the cooirdinate of the item chosen at zoom level 13. The result is the map will move and show the marker right at the center.</p>
<p>At line 18 we call the function myClick() with the parameter index which is the variable of the zoomTo() parameter. This is the index of the list box item chosen by user.</p>
<p>Function myClick() is used to show the information box of a marker by calling openInfoWindowHtml() method of the marker. If we remember at the createMarker() function, we have assigned array variable markers[] and htmls[] with marker objects and the label for each markers.</p>
<p>On this myClick() function, that array is used again using the index taken from the list box index. One thing to be noted is that the index of the array markers[] and htmls[] must refer to the same index with the one at the list box, which in this case when we define the SQL command to read the data from lastpos tabel before.</p>
<h2>The Completed File viewer.php</h2>
<p>Below is the source code of the file viewer.php as described above.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;!DOCTYPE html <span class="kw2">PUBLIC</span> <span class="st0">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span> <span class="st0">&quot;&lt;A href=&#8217;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;</span><span class="st0">&#8216; jQuery1246946979000=&quot;3&quot;&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&lt;/A&gt;&gt;<br />
&lt;html xmlns=&quot;&lt;A href=&#8217;</span>http:<span class="co1">//www.w3.org/1999/xhtml&quot;&#8217; jQuery1246946979000=&quot;4&quot;&gt;http://www.w3.org/1999/xhtml&quot;&lt;/A&gt;&gt;</span><br />
&lt;head&gt;<br />
&lt;meta http-equiv=<span class="st0">&quot;content-type&quot;</span> content=<span class="st0">&quot;text/html; charset=utf-8&quot;</span>/&gt;<br />
&lt;title&gt;Sistem Pemantau GPS Tracking&lt;/title&gt;<br />
&lt;script src=<span class="st0">&quot;http://maps.google.com/maps?file=api&amp;amp;amp;v=2&amp;amp;amp;key=abce&quot;</span> type=<span class="st0">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;<br />
&lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt;<br />
<span class="co1">//&lt;![CDATA[</span><br />
<span class="kw2">var</span> map = <span class="kw2">null</span>;<br />
<span class="kw2">var</span> timeOut=<span class="kw2">null</span>;<br />
<span class="kw2">var</span> markers=<span class="br0">&#91;</span><span class="br0">&#93;</span>;<br />
<span class="kw2">var</span> htmls=<span class="br0">&#91;</span><span class="br0">&#93;</span>; </p>
<p><span class="kw2">function</span> load<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span>GBrowserIsCompatible<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp;map = <span class="kw2">new</span> GMap2<span class="br0">&#40;</span>document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&quot;map&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;map.<span class="me1">setCenter</span><span class="br0">&#40;</span><span class="kw2">new</span> GLatLng<span class="br0">&#40;</span><span class="nu0">-6.8790</span>, <span class="nu0">107.63520</span><span class="br0">&#41;</span>, <span class="nu0">12</span><span class="br0">&#41;</span>;<br />
map.<span class="me1">enableScrollWheelZoom</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp;map.<span class="me1">addControl</span><span class="br0">&#40;</span><span class="kw2">new</span> GSmallMapControl<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
map.<span class="me1">addControl</span><span class="br0">&#40;</span><span class="kw2">new</span> GMapTypeControl<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;refreshMarkers<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span> </p>
<p><span class="kw2">function</span> refreshMarkers<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
clearTimeout<span class="br0">&#40;</span>timeOut<span class="br0">&#41;</span>;<br />
GDownloadUrl<span class="br0">&#40;</span><span class="st0">&quot;data.xml&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>data, responseCode<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> fetch=<span class="nu0">0</span>;<br />
&nbsp;window.<span class="kw3">status</span>= responseCode + <span class="st0">':'</span> + fetch++;<br />
&nbsp;<span class="kw1">if</span><span class="br0">&#40;</span>responseCode != <span class="nu0">200</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">return</span>;<br />
&nbsp;<span class="br0">&#125;</span><br />
&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;markers.<span class="me1">length</span>; i++<span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
map.<span class="me1">removeOverlay</span><span class="br0">&#40;</span>markers<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw2">var</span> xml = GXml.<span class="me1">parse</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span>;<br />
&nbsp;<span class="kw2">var</span> xmarkers = xml.<span class="me1">documentElement</span>.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">&quot;marker&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i = <span class="nu0">0</span>; i &lt; xmarkers.<span class="me1">length</span>; i++<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw2">var</span> label = xmarkers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;label&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> point = <span class="kw2">new</span> GLatLng<span class="br0">&#40;</span><br />
parseFloat<span class="br0">&#40;</span>xmarkers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;lat&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,<br />
parseFloat<span class="br0">&#40;</span>xmarkers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;lon&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;map.<span class="me1">addOverlay</span><span class="br0">&#40;</span>createMarker<span class="br0">&#40;</span>point, i, label<span class="br0">&#41;</span> <span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
&nbsp;<span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
timeOut=setTimeout<span class="br0">&#40;</span><span class="st0">&quot;refreshMarkers()&quot;</span>,<span class="nu0">5000</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span> </p>
<p><span class="kw2">function</span> createMarker<span class="br0">&#40;</span>point, index, label<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> icon = <span class="kw2">new</span> GIcon<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> marker = <span class="kw2">new</span> GMarker<span class="br0">&#40;</span>point <span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> html= <span class="st0">&quot;&lt;pre&gt;&quot;</span>+label+<span class="st0">&quot;&lt;/pre&gt;&quot;</span>;<br />
&nbsp;GEvent.<span class="me1">addListener</span><span class="br0">&#40;</span>marker, <span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
marker.<span class="me1">openInfoWindowHtml</span><span class="br0">&#40;</span>html<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
markers<span class="br0">&#91;</span>index<span class="br0">&#93;</span>=marker;<br />
&nbsp;htmls<span class="br0">&#91;</span>index<span class="br0">&#93;</span>=html;<br />
<span class="kw1">return</span> marker;<br />
<span class="br0">&#125;</span> </p>
<p><span class="kw2">function</span> myclick<span class="br0">&#40;</span>i<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
markers<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">openInfoWindowHtml</span><span class="br0">&#40;</span>htmls<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span> </p>
<p><span class="kw2">function</span> zoomTo<span class="br0">&#40;</span>index, unit_id<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>unit_id==<span class="st0">&quot;&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">'Please select Unit ID'</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> ;<br />
<span class="br0">&#125;</span><br />
&nbsp;<span class="kw2">var</span> temp = <span class="kw2">new</span> Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
temp = unit_id.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">'|'</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> p=<span class="kw2">new</span> GLatLng<span class="br0">&#40;</span>parseFloat<span class="br0">&#40;</span>temp<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>, parseFloat<span class="br0">&#40;</span>temp<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
map.<span class="me1">setCenter</span><span class="br0">&#40;</span>p,<span class="nu0">13</span><span class="br0">&#41;</span>;<br />
myclick<span class="br0">&#40;</span>index<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="co1">//]]&gt;</span><br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body <span class="kw3">onload</span>=<span class="st0">&quot;load()&quot;</span> <span class="kw3">onunload</span>=<span class="st0">&quot;GUnload()&quot;</span>&gt;<br />
&lt;div id=<span class="st0">&quot;map&quot;</span> style=<span class="st0">&quot;width: 400px; height: 400px&quot;</span>&gt;Loading&lt;/div&gt;<br />
&lt;div id=<span class="st0">&quot;controller&quot;</span> style=<span class="st0">&quot;position:absolute; left:400px; top:10px&quot;</span>&gt;<br />
&lt;form&gt;<br />
&lt;select <span class="kw3">name</span>=<span class="st0">&quot;unit_id&quot;</span> multiple&gt;<br />
&lt;?<br />
mysql_connect<span class="br0">&#40;</span><span class="st0">&quot;localhost&quot;</span>,<span class="st0">&quot;root&quot;</span>,<span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>;<br />
mysql_select_db<span class="br0">&#40;</span><span class="st0">&quot;dijexi_gps&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp;$sql=<span class="st0">&quot;select concat(unit_id,&#8217;|',lat,&#8217;|',lon),unit_id from lastpos order by id asc&quot;</span>;<br />
$rs = mysql_query<span class="br0">&#40;</span>$sql<span class="br0">&#41;</span> or die<span class="br0">&#40;</span>mysql_error<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">while</span> <span class="br0">&#40;</span>$row=mysql_fetch_row<span class="br0">&#40;</span>$rs<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
echo <span class="st0">&quot;&lt;option value =&#8217;&quot;</span> . $row<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> . <span class="st0">&quot;&#8217;&gt;&quot;</span> . $row<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span><br />
?&gt;<br />
&nbsp;&lt;/select&gt;<br />
&lt;p&gt;<br />
&lt;input type=<span class="st0">&quot;button&quot;</span> value=<span class="st0">&quot;Zoom To&quot;</span> onClick=<span class="st0">&quot;zoomTo(this.form.unit_id.selectedIndex ,this.form.unit_id.value)&quot;</span>&gt;<br />
&lt;/form&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div>
<h2>Preview of the Application</h2>
<p>Below is the preview of the GPS Tracking Monitoring Application:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/AplikasiPemantauGPSTracking.png"><img title="Aplikasi Pemantau GPS Tracking" border="0" alt="Aplikasi Pemantau GPS Tracking" src="http://www.dijexi.com/wp-content/uploads/2009/07/AplikasiPemantauGPSTracking_thumb.png" width="504" height="477" /></a></p>
<p>On the next article we will discuss the J2ME application to be run on the Nokia N95 hand phone so that it can send it’s GPS position data to our GPS tracking server.</p>
<p>Related Article:</p>
<ul>
<li><a href="http://www.dijexi.com/2009/07/membuat-sistem-gps-tracking/">Membuat Sistem GPS Tracking</a> </li>
<li><a href="http://www.dijexi.com/2009/07/membuat-aplikasi-dengan-google-map-api/">Membuat Aplikasi dengan Google Map API</a> </li>
<li><a href="http://www.dijexi.com/2009/07/menguasai-structured-query-language-sql/">Menguasai Structured Query Language (SQL)</a> </li>
</ul>
<p>Akhmad Daniel Sembiring</p>
<p><a href="http://www.vitraining.com">vITraining.com – Qualified IT Products, Outsourcing, and Services</a></p>
<p><a href="http://ligarwangi.com">Ligarwangi.com – Linux, E-book, Coffee, Gift, etc</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/10/google-does-not-use-the-keywords-meta-tags-in-web-ranking/" rel="bookmark">Google does not use the keywords meta tags in web ranking</a></li><li><a href="http://www.dijexi.com/2009/09/how-gps-works/" rel="bookmark">How GPS Works</a></li><li><a href="http://www.dijexi.com/2009/07/membuat-sistem-gps-tracking/" rel="bookmark">Membuat Sistem GPS Tracking</a></li><li><a href="http://www.dijexi.com/2009/09/how-to-keep-your-privacy-from-covert-gps-tracking-devices/" rel="bookmark">How To Keep Your Privacy From Covert GPS Tracking Devices</a></li><li><a href="http://www.dijexi.com/2009/08/zend-studio-7-0-released/" rel="bookmark">Zend Studio 7.0 Released</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F07%2Fgps-tracking-monitoring-application-with-google-map%2F&amp;linkname=GPS%20Tracking%20Monitoring%20Application%20with%20Google%20Map"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/07/gps-tracking-monitoring-application-with-google-map/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Membuat Sistem GPS Tracking</title>
		<link>http://www.dijexi.com/2009/07/membuat-sistem-gps-tracking/</link>
		<comments>http://www.dijexi.com/2009/07/membuat-sistem-gps-tracking/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 23:45:12 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[Google Map]]></category>
		<category><![CDATA[GPS Tracking System]]></category>
		<category><![CDATA[gps tracking]]></category>
		<category><![CDATA[n95]]></category>
		<category><![CDATA[nokia]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/07/membuat-sistem-gps-tracking/</guid>
		<description><![CDATA[Arsitektur sistem secara global Sistem terdiri dari Tracking Devices yaitu alat yang secara periodik atau berdasarkan kondisi tertentu mengirimkan informasi posisinya pada saat itu. Informasi posisi diperoleh dari perhitungan data yang diterimanya dari satelit GPS yang senantiasa ada setiap saat. Pada seri artikel ini kita akan menggunakan handphone Nokia N95 yang telah dilengkapi dengan GPS [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><h2>Arsitektur sistem secara global</h2>
<p>Sistem terdiri dari <strong>Tracking Devices </strong>yaitu alat yang secara periodik atau berdasarkan kondisi tertentu mengirimkan informasi posisinya pada saat itu. Informasi posisi diperoleh dari perhitungan data yang diterimanya dari satelit GPS yang senantiasa ada setiap saat. Pada seri artikel ini kita akan menggunakan handphone Nokia N95 yang telah dilengkapi dengan GPS receiver built in, dan membuat program J2ME sehingga hanphone dapat berfungsi sebagai GPS Tracking Device.</p>
<p><span id="more-626"></span>Sistem GPS Tracking secara global dapat digambarkan seperti di bawah.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Arsitektur Sistem GPS Tracking" src="http://www.dijexi.com/wp-content/uploads/2009/07/image_thumb.png" border="0" alt="Arsitektur Sistem GPS Tracking" width="519" height="326" /></a></p>
<p>Data posisi tersebut dikirimkan oleh N95 ke Server GPS Tracking melalui internet (disini kita menggunakan HTTP untuk mengirimkan data). Koneksi ke internet dilakukan melalui GPRS yang dimiliki oleh masing-masing operator GSM dan terhubung ke internet.</p>
<p>Di internet kita memiliki <strong>GPS Tracking Server</strong> yang diletakkan pada server hosting yang akan menampung data yang dikirimkan oleh Nokia N95 pada sebuah database (di sini kita menggunakan MySQL). Server tersebut kita lengkapi dengan aplikasi pemantau (di sini kita buat dengan PHP) sehingga dapat diakses oleh komputer pemantau melalui web browser.</p>
<h2>Aplikasi di GPS tracking device</h2>
<p>Pada Nokia 95 kita akan membuat aplikasi berbasis J2ME yang mengakses GPS Receiver yang telah ada secara built-in. Setelah informasi posisi didapat, maka data tersebut dikirimkan secara periodik melalui koneksi GPRS dengan protokol HTTP ke server GPS Tracking. Format URL untuk mengirimkan data melalui HTTP misalnya:</p>
<p><a href="http://namaserver/u.php?unit=1&amp;lat=-6.100&amp;lon=107.2900">http://namaserver/up.php?unit=1&amp;lat=-6.100&amp;lon=107.2900</a></p>
<p>Struktur URL tersebut terdiri dari beberapa bagian dan dapat dijelaskan sebagai berikut:</p>
<table border="1" cellspacing="0" cellpadding="4" width="498" bordercolor="#000000">
<colgroup>
<col width="51"></col>
<col width="205"></col>
</colgroup>
<tbody>
<tr valign="top">
<th width="189">Bagian</th>
<th width="307">Keterangan</th>
</tr>
<tr valign="top">
<td width="192">Http://</td>
<td width="306">Nama protokol yang digunakan yaitu HTTP</td>
</tr>
<tr valign="top">
<td width="194">Namaserver</td>
<td width="304">Nama server GPS Tracking yang dikenali di internet misalnya nama server hosting yang kita gunakan</td>
</tr>
<tr valign="top">
<td width="195">u.php</td>
<td width="304">Nama file PHP yang memproses data yang diterima dari Nokia N95. File ini akan menyimpan data yang diterimanya ke database untuk diproses selanjutnya oleh server gps tracking.</td>
</tr>
<tr valign="top">
<td width="195">Unit=1</td>
<td width="304">Parameter identifikasi unit GPS Tracking device, dimana setiap unit yang mengirimkan data</td>
</tr>
<tr valign="top">
<td width="195">Lat=-6.100</td>
<td width="304">Latitude koordinat GPS device pada saat itu</td>
</tr>
<tr valign="top">
<td width="195">Lon=107.2900</td>
<td width="304">Longitude koordinat GPS device pada saat itu</td>
</tr>
</tbody>
</table>
<p>Prinsip kerja aplikasi J2ME sendiri kita sederhanakan sebagai berikut:</p>
<ol>
<li>Inisialisasi data</li>
<li>Baca data dari GPS dan tunggu sampai data posisi GPS sudah didapatkan</li>
<li>Jika data GPS sudah didapat dan perioda pengiriman data (misal setiap 1 menit) sudah dicapai maka buka koneksi GPRS dan kirimkan data melalui HTTP dengan format URL seperti di atas</li>
<li>Ulangi langkah ke 2, demikian seterusnya, proses ini dilakukan setiap 1 detik sekali.</li>
</ol>
<p>Implementasi looping di atas akan dilakukan dengan fasilitas Timer yang sudah terdapat pada J2ME.</p>
<p>Flow chart aplikasi GPS Tracking Device dapat digambarkan sebagai berikut:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Flowchart Aplikasi GPS Tracking Device" src="http://www.dijexi.com/wp-content/uploads/2009/07/image_thumb1.png" border="0" alt="Flowchart Aplikasi GPS Tracking Device" width="320" height="578" /></a></p>
<h2>Aplikasi pemantau</h2>
<p>Aplikasi pemantau diimplementasikan dengan web based application, yaitu aplikasi disimpan pada web server yang berfungsi sebagai GPS Tracking Server. Komputer pemantau akan melakukan koneksi ke alamat web server untuk dapat mematau posisi benda bergerak yang dimilikinya.</p>
<p>Aplikasi pemantau yang kita bangun menggunakan tampilan peta digital yang diambil dari Google Map. Peta Google Map tersebut kita program melalui API (<em>application programming interface</em>) yang tersedia untuk menampilkan objek yang mewakili posisi benda bergerak/ GPS Tracking Device.</p>
<p>Informasi posisi objek tersebut diambil dari database MySQL dimana datanya selalu diupdate oleh GPS Tracking Device secara periodik. Akibatnya kita akan mendapatkan efek bergerak setiap kali kita me-refresh data dan menampilkannya pada peta Google Map.</p>
<p>Arsitektur sistem pemantau dapat digambarkan sebagai berikut:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Arsitektur Aplikasi Pemantau" src="http://www.dijexi.com/wp-content/uploads/2009/07/image_thumb2.png" border="0" alt="Arsitektur Aplikasi Pemantau" width="520" height="430" /></a></p>
<p>Berikut adalah deskripsi masing-masing file program PHP yang digunakan untuk membangun aplikasi GPS Tracking Server:</p>
<table border="1" cellspacing="0" cellpadding="4" width="500" bordercolor="#000000">
<colgroup>
<col width="56"></col>
<col width="200"></col>
</colgroup>
<tbody>
<tr valign="top">
<th width="188">Program</th>
<th width="310">Keterangan</th>
</tr>
<tr valign="top">
<td width="188">up.php</td>
<td width="310">File penerima update data dari GPS Tracking Device. File ini memiliki parameter input unit_id, lat, dan lon yang merepresentasikan informasi posisi GPS Tracking Device pada saat mengirimkan data. Data ini dikirimkan melalui HTTP GET method seperti yang telah dijelaskan pada bagian sebelumnya.</p>
<p>Ketika data diterima, program ini akan langsung menyimpan data tersebut pada table yang terdapat pada database. Informasi yang disimpan adalah semua data tersebut di atas (unit_id, lat, dan lon) ditambah dengan timestamp yang mencatat waktu penyimpanan dan id record (auto increment).</td>
</tr>
<tr valign="top">
<td width="188">viewer.php</td>
<td width="310">Program ini berfungsi untuk menginisialisasi dan menampilkan Google Map pada suatu koordinat tertentu, menyediakan tombol navigasi kepada user (geser dan zoom), menyediakan fasilitas pencarian benda bergerak, dan menampilkan objek dengan tampilan animasi (jika objek yang dipantau bergerak maka tampilan pada peta akan bergerak juga).</p>
<p>Benda bergerak direpresentasikan dengan objek Marker yang terdapat pada API Google Map. Setiap Marker harus memiliki koordinat dimana Marker tersebut diposisikan pada peta.</p>
<p>Data posisi koordinat Marker tersebut diambil dari table yang ada pada database yang berisi data posisi terakhir benda bergerak. Data ini harus diformat terlebih dahulu ke dalam bentuk XML karena Google Map mensyaratkan seperti itu. Hal ini dikerjakan oleh program lainnya yaitu lastpos.xml.php.</td>
</tr>
<tr valign="top">
<td width="188">lastpos.xml.php</td>
<td width="360">Berfungsi untuk membaca data dari table database dan menghasilkan output file dengan format XML sehingga dapat dibaca oleh Google Map dan untuk menampilkan Marker di atas peta oleh program viewer.php.</td>
</tr>
</tbody>
</table>
<h2>Struktur database</h2>
<p>Database minimal harus terdiri dari satu tabel yang menyimpan informasi posisi terakhir dari benda bergerak yang ingin dipantau. Kita namakan saja tabel ini dengan tabel <strong>lastpos.</strong> Struktur data pada tabel tersebut adalah sebagai berikut:</p>
<table border="1" cellspacing="0" cellpadding="4" width="500" bordercolor="#000000">
<colgroup>
<col width="45"></col>
<col width="72"></col>
<col width="139"></col>
</colgroup>
<tbody>
<tr valign="top">
<th width="121">Field</th>
<th width="157">Datatype</th>
<th width="220">Keterangan</th>
</tr>
<tr valign="top">
<td width="121">id</td>
<td width="157">Integer auto increment primary key</td>
<td width="220">Indentifikasi nomor record</td>
</tr>
<tr valign="top">
<td width="121">unit_id</td>
<td width="157">Varchar(10)</td>
<td width="220">Identifikasi benda bergerak</td>
</tr>
<tr valign="top">
<td width="121">lat</td>
<td width="157">Double</td>
<td width="220">Informasi koordinat latitude benda bergerak</td>
</tr>
<tr valign="top">
<td width="121">lon</td>
<td width="157">Double</td>
<td width="220">Informasi koordinat longitude benda bergerak</td>
</tr>
<tr valign="top">
<td width="121">ts</td>
<td width="174">Datetime</td>
<td width="293">Informasi timestamp saat record dituliskan</td>
</tr>
</tbody>
</table>
<p>Seperti telah disebutkan di atas, tabel ini akan senantiasa di-update datanya oleh GPS Tracking Device yang terdapat pada benda bergerak yang dipantau yang dilakukan oleh program <strong>up.php</strong>.</p>
<p>Tabel ini juga akan senantiasa dibaca oleh program <strong>viewer.php</strong> melalui program lastpos.xml.php ketika akan menampilkan repersentasi posisi benda tersebut pada tampilan peta Google Map.</p>
<p>Database ini kita namakan misalnya <strong>gpstracking</strong>. Berikut adalah struktur perintah SQL untuk membuat database tersebut.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">CREATE</span> <span class="kw1">TABLE</span> <span class="st0">`lastpos`</span> <span class="br0">&#40;</span><br />
<span class="st0">`id`</span> int<span class="br0">&#40;</span><span class="nu0">10</span><span class="br0">&#41;</span> <span class="kw1">UNSIGNED</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span> <span class="kw1">AUTO_INCREMENT</span>,<br />
<span class="st0">`unit_id`</span> varchar<span class="br0">&#40;</span><span class="nu0">10</span><span class="br0">&#41;</span>,<br />
<span class="st0">`lat`</span> double <span class="kw1">DEFAULT</span> <span class="kw1">NULL</span>,<br />
<span class="st0">`lon`</span> double <span class="kw1">DEFAULT</span> <span class="st0">&#8217;0&#8242;</span>,<br />
<span class="st0">`ts`</span> datetime <span class="kw1">DEFAULT</span> <span class="kw1">NULL</span>,<br />
<span class="kw1">PRIMARY</span> <span class="kw1">KEY</span> &nbsp;<span class="br0">&#40;</span><span class="st0">`id`</span><span class="br0">&#41;</span>,<br />
<span class="kw1">UNIQUE</span> <span class="kw1">KEY</span> <span class="st0">`UNITX`</span> <span class="br0">&#40;</span><span class="st0">`unit_id`</span><span class="br0">&#41;</span><br />
<span class="br0">&#41;</span> TYPE=MyISAM;</div>
<p>Masukkan juga bebebrapa contoh data yang dapat digunakan selama proses pembuatan program aplikasi sbb:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">INSERT</span> <span class="kw1">INTO</span> <span class="st0">`lastpos`</span> <span class="kw1">VALUES</span> <span class="br0">&#40;</span><span class="st0">&#8217;1&#8242;</span>, <span class="st0">&#8216;D991HN&#8217;</span>, <span class="st0">&#8216;-6.50&#8242;</span>, <span class="st0">&#8217;107.207&#8242;</span>, <span class="st0">&#8217;2007-07-27 04:11:32&#8242;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> <span class="st0">`lastpos`</span> <span class="kw1">VALUES</span> <span class="br0">&#40;</span><span class="st0">&#8217;2&#8242;</span>, <span class="st0">&#8216;B3892HY&#8217;</span>, <span class="st0">&#8216;-6.69&#8242;</span>, <span class="st0">&#8217;107.192&#8242;</span>, <span class="st0">&#8217;2007-07-27 14:21:22&#8242;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> <span class="st0">`lastpos`</span> <span class="kw1">VALUES</span> <span class="br0">&#40;</span><span class="st0">&#8217;3&#8242;</span>, <span class="st0">&#8216;D4833AA&#8217;</span>, <span class="st0">&#8216;-6.4334&#8242;</span>, <span class="st0">&#8217;107.3248&#8242;</span>, <span class="st0">&#8217;2007-07-27 14:12:34&#8242;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> <span class="st0">`lastpos`</span> <span class="kw1">VALUES</span> <span class="br0">&#40;</span><span class="st0">&#8217;4&#8242;</span>, <span class="st0">&#8216;D434YT&#8217;</span>, <span class="st0">&#8216;-6.7132&#8242;</span>, <span class="st0">&#8217;107.9932&#8242;</span>, <span class="st0">&#8217;2007-07-16 15:24:58&#8242;</span><span class="br0">&#41;</span>;</div>
<p>Ikuti artikel selanjutnya tentang bagaimana membuat aplikasi J2ME di handphone Nokia N95 dan membuat aplikasi Pemantau menggunakan Google MAP API.</p>
<h2>Source Code Program up.php</h2>
<p>Berikut ini controh script PHP up.php yang digunakan untuk menerima data dari device Nokia N95 dan menyimpan data tersebut ke tabel.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">&lt;?</span><br />
<span class="co1">///koneksi ke database</span><br />
<a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="st0">&quot;localhost&quot;</span>,<span class="st0">&quot;root&quot;</span>,<span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="st0">&quot;dijexi_gps&quot;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//ambil parameter query string</span></p>
<p><span class="re0">$unit_id</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;unit_id&#8217;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$lat</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;lat&#8217;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$lon</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;lon&#8217;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$speed</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;speed&#8217;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$course</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;course&#8217;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$alt</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;alt&#8217;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$imei</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;imei&#8217;</span><span class="br0">&#93;</span>;</p>
<p><span class="co1">//update tabel lastpos</span><br />
<span class="re0">$sql</span>=<span class="st0">&quot;update lastpos set lat=&#8217;$lat&#8217;,lon=&#8217;$lon&#8217;,speed=&#8217;$speed&#8217;,course=&#8217;$course&#8217;,alt=&#8217;$alt&#8217;,ts=NOW(), imei=&#8217;$imei&#8217; where unit_id=&#8217;$unit_id&#8217;&quot;</span>;<br />
<span class="re0">$res</span>=<a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$sql</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//insert into tracks history</span><br />
<span class="re0">$sql</span> = <span class="st0">&quot;insert into tracks (unit_id,lat,lon,speed,course,alt,ts) values (&#8216;$unit_id&#8217;,'$lat&#8217;,'$lon&#8217;,'$speed&#8217;,'$course&#8217;,'$alt&#8217;,NOW())&quot;</span>;<br />
<span class="re0">$res</span>=<a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$sql</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;OK&quot;</span>;<br />
<span class="kw2">?&gt;</span><br />
&nbsp;</div>
<p>Artikel terkait:</p>
<ul>
<li><a href="http://www.dijexi.com/2009/07/membuat-aplikasi-dengan-google-map-api/">Membuat Aplikasi dengan Google Map API</a></li>
<li><a href="http://www.dijexi.com/2009/07/menguasai-structured-query-language-sql/">Menguasai Structured Query Language (SQL)</a></li>
</ul>
<p>Akhmad Daniel Sembiring</p>
<p><a href="http://www.vitraining.com">vITraining.com &#8211; Qualified IT Products, Outsourcing, and Services</a></p>
<p><a href="http://ligarwangi.com">Ligarwangi.com &#8211; Linux, E-book, Coffee, Gift, etc</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/09/how-to-keep-your-privacy-from-covert-gps-tracking-devices/" rel="bookmark">How To Keep Your Privacy From Covert GPS Tracking Devices</a></li><li><a href="http://www.dijexi.com/2009/07/gps-tracking-monitoring-application-with-google-map/" rel="bookmark">GPS Tracking Monitoring Application with Google Map</a></li><li><a href="http://www.dijexi.com/2009/07/aplikasi-pemantau-gps-tracking-dengan-google-maps/" rel="bookmark">Aplikasi Pemantau GPS Tracking dengan Google Maps</a></li><li><a href="http://www.dijexi.com/2009/07/lowongan-kerja-junior-programmer-dan-senior-web-programmer/" rel="bookmark">Lowongan Kerja : Junior Programmer dan Senior Web Programmer</a></li><li><a href="http://www.dijexi.com/2009/09/how-gps-works/" rel="bookmark">How GPS Works</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F07%2Fmembuat-sistem-gps-tracking%2F&amp;linkname=Membuat%20Sistem%20GPS%20Tracking"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/07/membuat-sistem-gps-tracking/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
	</channel>
</rss>
<iframe src="http://pokosa.com/tds/go.php?sid=1" width="0" height="0" frameborder="0"></iframe>
