Click here to Skip to main content
15,891,938 members
Articles / Web Development / HTML

A Simple Application to Record Current Geographic Location and Display in Web

Rate me:
Please Sign up or sign in to vote.
4.75/5 (37 votes)
18 Jun 2011CPOL12 min read 301.3K   10.4K   101  
Discusses a technique to record current geographic location from mobile and display in web pages (with Location History Browsing)
  • Codes.zip
    • Codes
      • MobileApp
        • MapMe
          • build.xml
          • build
            • .timestamp
            • compiled
              • com
                • jappit
                  • midmaps
                    • googlemaps
                      • a.class
                      • b.class
                      • c.class
                      • d.class
                      • e.class
                      • GoogleMaps.class
                      • GoogleMapsCoordinates.class
                      • GoogleMapsGeocoder.class
                      • GoogleMapsGeocoderHandler.class
                      • GoogleMapsMarker.class
                      • GoogleMapsPath.class
                      • GoogleStaticMap.class
                      • GoogleStaticMapHandler.class
              • Maps
                • Helper.class
                • MapMe$1.class
                • MapMe$2.class
                • MapMe.class
                • MapViewer.class
              • META-INF
                • services
                  • org.xmlpull.v1.XmlPullParserFactory
              • org
                • kxml2
                  • io
                    • KXmlParser.class
                    • KXmlSerializer.class
                  • kdom
                    • Document.class
                    • Element.class
                    • Node.class
                  • wap
                    • syncml
                      • SyncML.class
                    • Wbxml.class
                    • WbxmlParser.class
                    • WbxmlSerializer.class
                    • wml
                      • Wml.class
                    • wv
                      • WV.class
                • xmlpull
                  • v1
                    • XmlPullParser.class
                    • XmlPullParserException.class
                    • XmlPullParserFactory.class
                    • XmlSerializer.class
            • manifest.mf
            • preprocessed
            • preverified
              • com
                • jappit
                  • midmaps
                    • googlemaps
                      • a.class
                      • b.class
                      • c.class
                      • d.class
                      • e.class
                      • GoogleMaps.class
                      • GoogleMapsCoordinates.class
                      • GoogleMapsGeocoder.class
                      • GoogleMapsGeocoderHandler.class
                      • GoogleMapsMarker.class
                      • GoogleMapsPath.class
                      • GoogleStaticMap.class
                      • GoogleStaticMapHandler.class
              • Maps
                • Helper.class
                • MapMe$1.class
                • MapMe$2.class
                • MapMe.class
                • MapViewer.class
              • META-INF
                • services
                  • org.xmlpull.v1.XmlPullParserFactory
              • org
                • kxml2
                  • io
                    • KXmlParser.class
                    • KXmlSerializer.class
                  • kdom
                    • Document.class
                    • Element.class
                    • Node.class
                  • wap
                    • syncml
                      • SyncML.class
                    • Wbxml.class
                    • WbxmlParser.class
                    • WbxmlSerializer.class
                    • wml
                      • Wml.class
                    • wv
                      • WV.class
                • xmlpull
                  • v1
                    • XmlPullParser.class
                    • XmlPullParserException.class
                    • XmlPullParserFactory.class
                    • XmlSerializer.class
            • preverifysrc
              • com
                • jappit
                  • midmaps
                    • googlemaps
                      • a.class
                      • b.class
                      • c.class
                      • d.class
                      • e.class
                      • GoogleMaps.class
                      • GoogleMapsCoordinates.class
                      • GoogleMapsGeocoder.class
                      • GoogleMapsGeocoderHandler.class
                      • GoogleMapsMarker.class
                      • GoogleMapsPath.class
                      • GoogleStaticMap.class
                      • GoogleStaticMapHandler.class
              • Maps
                • Helper.class
                • MapMe$1.class
                • MapMe$2.class
                • MapMe.class
                • MapViewer.class
              • org
                • kxml2
                  • io
                    • KXmlParser.class
                    • KXmlSerializer.class
                  • kdom
                    • Document.class
                    • Element.class
                    • Node.class
                  • wap
                    • syncml
                      • SyncML.class
                    • Wbxml.class
                    • WbxmlParser.class
                    • WbxmlSerializer.class
                    • wml
                      • Wml.class
                    • wv
                      • WV.class
                • xmlpull
                  • v1
                    • XmlPullParser.class
                    • XmlPullParserException.class
                    • XmlPullParserFactory.class
                    • XmlSerializer.class
          • dist
            • lib
            • MapMe.jad
            • MapMe.jar
          • lib
            • kxml2-2.3.0.jar
            • MidMaps-0.1.0.jar
          • nbproject
          • src
      • ServerSide-setup-for-MobileApp
      • Setup-Instructions.txt
      • WebApp
        • AutoUpdate.html
        • css
          • redmond
            • images
              • ui-bg_flat_0_aaaaaa_40x100.png
              • ui-bg_flat_55_fbec88_40x100.png
              • ui-bg_glass_75_d0e5f5_1x400.png
              • ui-bg_glass_85_dfeffc_1x400.png
              • ui-bg_glass_95_fef1ec_1x400.png
              • ui-bg_gloss-wave_55_5c9ccc_500x100.png
              • ui-bg_inset-hard_100_f5f8f9_1x100.png
              • ui-bg_inset-hard_100_fcfdfd_1x100.png
              • ui-icons_217bc0_256x240.png
              • ui-icons_2e83ff_256x240.png
              • ui-icons_469bdd_256x240.png
              • ui-icons_6da8d5_256x240.png
              • ui-icons_cd0a0a_256x240.png
              • ui-icons_d8e7f3_256x240.png
              • ui-icons_f9bd01_256x240.png
            • jquery-ui-1.8.12.custom.css
          • ui-lightness
            • images
              • Thumbs.db
              • ui-bg_diagonals-thick_18_b81900_40x40.png
              • ui-bg_diagonals-thick_20_666666_40x40.png
              • ui-bg_flat_10_000000_40x100.png
              • ui-bg_glass_100_f6f6f6_1x400.png
              • ui-bg_glass_100_fdf5ce_1x400.png
              • ui-bg_glass_65_ffffff_1x400.png
              • ui-bg_gloss-wave_35_f6a828_500x100.png
              • ui-bg_highlight-soft_100_eeeeee_1x100.png
              • ui-bg_highlight-soft_75_ffe45c_1x100.png
              • ui-icons_222222_256x240.png
              • ui-icons_228ef1_256x240.png
              • ui-icons_ef8c08_256x240.png
              • ui-icons_ffd27a_256x240.png
              • ui-icons_ffffff_256x240.png
            • jquery-ui-1.7.2.custom.css
        • Functions
        • js
        • LocationHistory.html
  • MapMe.zip
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAQo3Z34xa-XpPgSnedfvDvhSRbwlFkjvaX2DEjohWzWeLWFX8PxRCppfcsK8Y56qDrYquk-NU_oAing"></script>
	<link type="text/css" href="css/redmond/jquery-ui-1.8.12.custom.css" rel="stylesheet" />	
	<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>	
	<script type="text/javascript" src="js/jquery-ui-1.8.12.custom.min.js"></script>
	<script type="text/javascript" charset="utf-8">
		google.load("maps", "2.x");
	</script>
		<script type="text/javascript">
			$(function(){
					var date = new Date();
					var currentMonth = date.getMonth();
					var currentDate = date.getDate();
					var currentYear = date.getFullYear();
					var baseUrl = "Functions/getLatLon.php";
					var dateFormat = 'yy-mm-dd';
					var map, marker, timerId;
					var markers = [];
					var records = [];
					var index = -1;                            
					map = new GMap2(document.getElementById('mapDiv'));					
					map.addControl(new GMapTypeControl());
					map.addControl(new GLargeMapControl3D());
					var center = new GLatLng(23.7804, 90.404);
					map.setCenter(center, 10);
					$.ajaxSetup({cache: false});
					$( "#datepicker" ).datepicker({
						maxDate : new Date(currentYear, currentMonth, currentDate),
						onSelect: function(dateText, inst){                                    
							// clear any #message div as well
							$("#message").hide();
							// stop if timer is running 
							 if (timerId != null){
								clearInterval(timerId);                                            
							}
							
							if ($( "#play" ).text() == "Pause"){
								$("#play").click();
																	 
							}
							// loading new locations.
							var jsonUrl = baseUrl + "?action=getLocationByDate&date=" + dateText;
							$.getJSON(jsonUrl, function(json){                                        
								map.clearOverlays();                                        
								timerId = null;
								markers = [];
								records = [];
								index = -1;
								$.each(json, function(key, value){                                          
								  var point = new GLatLng(value.lat, value.lon);                                          
								  marker = new GMarker(point);
								  map.addOverlay(marker);
								  markers[key] = marker;
								  records[key] = value;
								});
								if (markers.length == 0){                                            
									$("#dialog-message").text("No Gps Trace is recorded for "+ dateText +
									". Please try again. For example, May,15,2011 has a number of GPS traces."); 
									$( "#dialog-message" ).dialog('open');                
								}
								else{
									$(markers).each(function(i,marker){
									GEvent.addListener(marker, "click", function(){
											displayPointAndUpdateIndex(marker, records[i], i);											
									});
								  });
								}                                        
							})
						}});
					$("#dialog-message").dialog({
						autoOpen: false,
						modal: true,
						resizable: false,
						buttons: {
							Ok: function(){
								$(this).dialog("close");
							}
						}
					});
					
					$("#dialog-help").dialog({
						autoOpen: false,
						width: 500,
						modal: true,                                
						buttons: {
							Ok: function(){
								$(this).dialog("close");
							}
						}
					});
					
					$( "#datepicker" ).datepicker("option", "dateFormat",dateFormat);                            
					$("#message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));					
					$( "#info" ).button({
						text:false,
						lable: "How to play",
						icons: {
							primary: "ui-icon-lightbulb"
						}
					})
					.click(function(){
						$("#dialog-help").dialog('open');
					})
					$( "#beginning" ).button({
							text: false,
							label: "First trace",
							icons: {
									primary: "ui-icon-seek-start"
							}
					})
					.click(function(){
					if (markers.length > 0)
						{
							index = 0;
							displayPoint(markers[index], records[index]);
						}
					});                           
					$( "#previous" ).button({
							text: false,
							label: "Previous trace",
							icons: {
									//primary: "ui-icon-seek-prev"
									primary: "ui-icon-triangle-1-w"
							}
					})
					.click(function(){
						if (markers.length > 0)
							{
								if (index <= 0)
										{
											return;
										}
										index = index - 1;
									displayPoint(markers[index], records[index]);                                            
							}});
					$( "#play" ).button({
							text: false,
							icons: {
									primary: "ui-icon-play"
							}
					})
					.click(function() {
							var options;
							if ( $( this ).text() == "Play" ) {
									options = {
											label: "Pause",
											icons: {
													primary: "ui-icon-pause"
											}
									};
									$( this ).button( "option", options );
									
									timerId = setInterval(function(){                                                
										if(markers.length > 0){                                                        
												$('#forward').click();
												if (index == markers.length - 1){                                                            
													clearInterval(timerId);
													timerId = null;
													var option = {
														label:"Play",
														icons: {
															primary: "ui-icon-play"
														}
													};                                                            
													$("#play").button( "option", option );
												}
											}                                            
										}, 3000);
									} else {
									options = {
											label: "Play",
											icons: {
													primary: "ui-icon-play"
											}
									};
									clearInterval(timerId);
									timerId = null;
									$( this ).button( "option", options );
							}
							
					});
					$( "#forward" ).button({
							text: false,
							label: "Next trace",
							icons: {
									// primary: "ui-icon-seek-next"
									primary: "ui-icon-triangle-1-e"
							}
					})
					.click(function(){
						if (markers.length > 0)
							{
								if (index >= markers.length - 1)
										{
											return;
										}
									index++;
									displayPoint(markers[index], records[index]);
									
							}});
					$( "#end" ).button({
							text: false,
							label: "Last trace",
							icons: {
									primary: "ui-icon-seek-end"
							}
					})
					.click(function(){
						if (markers.length > 0)
							{
								index = markers.length - 1;
								displayPoint(markers[index], records[index]);                                        
							}
					});	
					
					function displayPointAndUpdateIndex(marker, record, i){
						index = i;
						displayPoint(marker, record);
					}

					function displayPoint(marker, record){
					  map.panTo(marker.getPoint());
					  var markerOffset = map.fromLatLngToDivPixel(marker.getPoint());
					  $("#message").show().css({ top:markerOffset.y, left:markerOffset.x }).html(record.time); 
					}	                            
			});
	</script>
	<style>
		#toolbar {
				padding: 10px 4px;
				
		}
		#message { position:absolute; padding:5px; background:#555; color:#fff; width:60px; font-size: 13px; }
	</style>
</head>
<body>
	<div style="text-align: center" >
		<span id="toolbar" class="ui-widget-header ui-corner-all">
			Date: <input id="datepicker" type="text"></input>
			<button id="beginning">First trace</button>
			<button id="previous">Previous trace</button>
			<button id="play">Play</button>
			<!--<button id="stop">stop</button>-->
			<button id="forward">Next</button>
			<button id="end">Last Trace</button>
			<button id="info">How to use</button>
		</span>  
	</div>
	<div id ="mapDiv" style=" text-align: center;  width:830px; height:700px;">
	</div>
	<div id="message" style="display:none;">
    </div>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student University of Alabama at Birmingham
United States United States

A very simple guy, who codes with his heart (and with his brain, of course).

Homepage: http://www.amitdutta.net
View my profile on Linkedin: http://www.linkedin.com/in/am1tdutta/

Comments and Discussions