{"id":524,"date":"2011-07-26T10:22:06","date_gmt":"2011-07-26T07:22:06","guid":{"rendered":"https:\/\/polyetilen.lt\/?p=524"},"modified":"2023-05-02T10:38:42","modified_gmt":"2023-05-02T07:38:42","slug":"android-geolocation-application-demo-using-phonegap-jquery-mobile-and-google-maps","status":"publish","type":"post","link":"https:\/\/polyetilen.lt\/en\/android-geolocation-application-demo-using-phonegap-jquery-mobile-and-google-maps","title":{"rendered":"Android geolocation application demo using PhoneGap, jQuery Mobile and Google Maps"},"content":{"rendered":"<p><div id='gallery-1' class='gallery galleryid-524 gallery-columns-1 gallery-size-medium'><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon landscape'>\n\t\t\t\t<a href='https:\/\/polyetilen.lt\/wp-content\/uploads\/2011\/07\/android_emulator_google_map.jpg'><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"588\" src=\"https:\/\/polyetilen.lt\/wp-content\/uploads\/2011\/07\/android_emulator_google_map-640x588.jpg\" class=\"attachment-medium size-medium\" alt=\"\" srcset=\"https:\/\/polyetilen.lt\/wp-content\/uploads\/2011\/07\/android_emulator_google_map-640x588.jpg 640w, https:\/\/polyetilen.lt\/wp-content\/uploads\/2011\/07\/android_emulator_google_map-900x827.jpg 900w, https:\/\/polyetilen.lt\/wp-content\/uploads\/2011\/07\/android_emulator_google_map.jpg 956w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a>\n\t\t\t<\/dt><\/dl><br style=\"clear: both\" \/>\n\t\t<\/div>\n<br \/>\nThis android geolocation application uses PhoneGap api for phone geo position and displays the phone position point on Google Maps. jQuery Mobile is used to display the page header, footer and content map. Page is resized to full height and width for any orientation or window size. Made with Eclipse and Android SDK. This demo also works on Chrome browser. <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt; \r\n&lt;head&gt;\r\n    &lt;meta charset=&quot;utf-8&quot;&gt;\r\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, minimum-scale=1, maximum-scale=1&quot;&gt;\r\n    &lt;title&gt;Map&lt;\/title&gt;\r\n    \r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;css\/jquery.mobile-1.0.1.css&quot; \/&gt;\r\n    \r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;js\/jquery-1.6.4.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;js\/jquery.mobile-1.0.1.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/www.google.com\/jsapi&quot;&gt;&lt;\/script&gt;\r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;js\/cordova-1.5.0.js&quot;&gt;&lt;\/script&gt;\r\n    \r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n\r\nvar map;\r\nvar marker;\r\nvar infowindow;\r\nvar watchID;\r\n\r\n$(document).ready(function(){\r\n\tdocument.addEventListener(&quot;deviceready&quot;, onDeviceReady, false);\r\n\t\/\/for testing in Chrome browser uncomment\r\n\t\/\/onDeviceReady();\r\n});\r\n\r\n\/\/PhoneGap is ready function\r\nfunction onDeviceReady() {\r\n\t$(window).unbind();\r\n\t$(window).bind('pageshow resize orientationchange', function(e){\r\n\t\tmax_height();\r\n\t});\r\n\tmax_height();\r\n\tgoogle.load(&quot;maps&quot;, &quot;3.8&quot;, {&quot;callback&quot;: map, other_params: &quot;sensor=true&amp;language=en&quot;});\r\n}\r\n\r\nfunction max_height(){\r\n\tvar h = $('div&#x5B;data-role=&quot;header&quot;]').outerHeight(true);\r\n\tvar f = $('div&#x5B;data-role=&quot;footer&quot;]').outerHeight(true);\r\n\tvar w = $(window).height();\r\n\tvar c = $('div&#x5B;data-role=&quot;content&quot;]');\r\n\tvar c_h = c.height();\r\n\tvar c_oh = c.outerHeight(true);\r\n\tvar c_new = w - h - f - c_oh + c_h;\r\n\tvar total = h + f + c_oh;\r\n\tif(c_h&lt;c.get(0).scrollHeight){\r\n\t\tc.height(c.get(0).scrollHeight);\r\n\t}else{\r\n\t\tc.height(c_new);\r\n\t}\r\n}\r\n\t\t\r\nfunction map(){\r\n    var latlng = new google.maps.LatLng(55.17, 23.76);\r\n    var myOptions = {\r\n      zoom: 6,\r\n      center: latlng,\r\n\t  streetViewControl: true,\r\n      mapTypeId: google.maps.MapTypeId.ROADMAP,\r\n      zoomControl: true\r\n    };\r\n    map = new google.maps.Map(document.getElementById(&quot;map&quot;), myOptions);\r\n\t\r\n\tgoogle.maps.event.addListenerOnce(map, 'tilesloaded', function(){\r\n\t\t\/\/get geoposition once\r\n\t\t\/\/navigator.geolocation.getCurrentPosition(geo_success, geo_error, { maximumAge: 5000, timeout: 5000, enableHighAccuracy: true });\r\n\t\t\/\/watch for geoposition change\r\n\t\twatchID = navigator.geolocation.watchPosition(geo_success, geo_error, { maximumAge: 5000, timeout: 5000, enableHighAccuracy: true });   \r\n\t}); \r\n}\r\n\r\nfunction geo_error(error){\r\n\t\/\/comment\r\n    alert('code: ' + error.code + '\\n' + 'message: ' + error.message + '\\n');\r\n}\r\n\r\nfunction geo_success(position) {\r\n\t\r\n\tmap.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));\r\n\tmap.setZoom(15);\r\n\r\n    var info = \r\n    ('Latitude: '         + position.coords.latitude          + '&lt;br&gt;' +\r\n    'Longitude: '         + position.coords.longitude         + '&lt;br&gt;' +\r\n    'Altitude: '          + position.coords.altitude          + '&lt;br&gt;' +\r\n    'Accuracy: '          + position.coords.accuracy          + '&lt;br&gt;' +\r\n    'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '&lt;br&gt;' +\r\n    'Heading: '           + position.coords.heading           + '&lt;br&gt;' +\r\n    'Speed: '             + position.coords.speed             + '&lt;br&gt;' +\r\n    'Timestamp: '         + new Date(position.timestamp));\r\n\r\n\tvar point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);\r\n\tif(!marker){\r\n\t\t\/\/create marker\r\n\t\tmarker = new google.maps.Marker({\r\n\t\t\tposition: point,\r\n\t\t\tmap: map\r\n\t\t});\r\n\t}else{\r\n\t\t\/\/move marker to new position\r\n\t\tmarker.setPosition(point);\r\n\t}\r\n\tif(!infowindow){\r\n\t\tinfowindow = new google.maps.InfoWindow({\r\n\t\t    content: info\r\n\t\t});\r\n\t}else{\r\n\t\tinfowindow.setContent(info);\r\n\t}\r\n\tgoogle.maps.event.addListener(marker, 'click', function() {\r\n\t  infowindow.open(map,marker);\r\n\t}); \r\n}\r\n&lt;\/script&gt;\r\n\r\n&lt;\/head&gt; \r\n&lt;body&gt; \r\n\r\n&lt;div data-role=&quot;page&quot; id=&quot;index&quot;&gt;\r\n\t&lt;div data-role=&quot;header&quot; data-theme=&quot;b&quot;&gt;&lt;h1&gt;Map Header&lt;\/h1&gt;&lt;\/div&gt;\r\n\t&lt;div data-role=&quot;content&quot; style=&quot;padding:0;&quot;&gt;\r\n\t\t&lt;div id=&quot;map&quot; style=&quot;width:100%;height:100%;&quot;&gt;&lt;\/div&gt;\r\n\t&lt;\/div&gt;\r\n\t&lt;div data-role=&quot;footer&quot; data-theme=&quot;b&quot;&gt;&lt;h4&gt;Map Footer&lt;\/h4&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Download Map android application Eclipse project source <a href=\"https:\/\/polyetilen.lt\/wp-content\/uploads\/2023\/05\/map.7z\">map.7z<\/a>, project source with jquery mobile version 1.4.3 and multipage demo <a href=\"https:\/\/polyetilen.lt\/wp-content\/uploads\/2023\/05\/map3.7z\">map3.7z<\/a>.<\/p>\n<p><strong>Build Android Application from project source<\/strong><br \/>\nFirst you will need Android SDK download and install from here <a href=\"http:\/\/developer.android.com\/sdk\/index.html\">developer.android.com\/sdk\/index.html<\/a>.<br \/>\nIf you install not ADT Bundle, the you need Eclipse IDE and ADT Plugin for Eclipse. For ADT Bundle just skip next downloads.<br \/>\nDownload and install Eclipse IDE for Java EE Developers <a href=\"http:\/\/www.eclipse.org\/downloads\/\">www.eclipse.org\/downloads\/<\/a><br \/>\nDownload and install ADT Plugin for Eclipse <a href=\"http:\/\/developer.android.com\/sdk\/eclipse-adt.html\">developer.android.com\/sdk\/eclipse-adt.html<\/a>.<br \/>\nNow you have powerful integrated environment in which you can build Android applications. <\/p>\n<p><strong>Import project files to Eclipse<\/strong><br \/>\nDownload map.7z file and extract files with 7-Zip archiver <a href=\"http:\/\/www.7-zip.org\">www.7-zip.org<\/a>.<br \/>\nStart Eclipse.<br \/>\nSelect File -> Import... -> General -> Existing Projects into Workspace.<br \/>\nSelect root directory, browse for folder with extracted map.7z files.<br \/>\nPress Finish.<\/p>\n<p><strong>Fix Android project properties<\/strong><br \/>\nFrom Eclipce project pane right-click on Map project and select \"Android Tools -> Fix Project Properties\". You can skip this step if there is no errors with project.<\/p>\n<p><strong>Create AVD<\/strong><br \/>\nStart AVD (Android Virtual Device) Manager and create new android virtual device with platform version greater 2.2 and start device (or Eclipce will start it after building project)<\/p>\n<p><strong>Build application<\/strong><br \/>\nFrom Eclipse project pane right-click on imported Map project and select Run As -> Android Application. After a few seconds, the project is being built and installed to your android virtual device. Also you can test application in Chrome browser just open map\\assets\\www\\index.html file from localhost or other host because Chrome has a security restriction with disabled navigator for the file protocol.<\/p>\n<p><strong>AVD Geoposition<\/strong><br \/>\nIf you see error message, then you need to set geoposition. Android virtual device don't emulate gps so you need to set manually geoposition via telnet. Open windows command line (for windows start -> run.. -> cmd), connect to your device and fix geo position. The port number can be seen in the title area of android emulator.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntelnet localhost 5554\r\ngeo fix 25.28 54.68\r\n<\/pre>\n<p><strong>Installing APK Application on Android virtual device<\/strong><br \/>\nOf course you can skip building and immediately install Map.apk file from bin folder. Then you will need Android SDK installed and start Android virtual device. Next start command line (for windows start -> run.. -> cmd) and install by command<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nC:\\progra~1\\Android\\android-sdk\\platform-tools\\adb.exe install Z:\\android\\project\\map\\bin\\Map.apk\r\n<\/pre>\n<p>change path for Map.apk where files are extracted.<\/p>\n<p><strong>More information<\/strong><br \/>\n<a href=\"http:\/\/jquery.com\/\">jQuery<\/a> JavaScript library<br \/>\n<a href=\"http:\/\/jquerymobile.com\/\">jQuery Mobile<\/a> HTML5-based user interface system for all popular mobile device platforms<br \/>\n<a href=\"http:\/\/phonegap.com\/start#android\">Phonegap get started guide for Android<\/a><br \/>\n<a href=\"https:\/\/developers.google.com\/maps\/\">Google Maps API<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This android geolocation application uses PhoneGap api for phone geo position and displays the phone position point on Google Maps. jQuery Mobile is used to display the page header, footer and content map. Page is &hellip; <a href=\"https:\/\/polyetilen.lt\/en\/android-geolocation-application-demo-using-phonegap-jquery-mobile-and-google-maps\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"http:\/\/polyetilen.lt\/?p=224","footnotes":""},"categories":[8],"tags":[80,79,78,67,77],"class_list":["post-524","post","type-post","status-publish","format-standard","hentry","category-programavimas","tag-android","tag-geo","tag-google-maps","tag-jquery-mobile","tag-phonegap","en-US"],"_links":{"self":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts\/524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/comments?post=524"}],"version-history":[{"count":4,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts\/524\/revisions"}],"predecessor-version":[{"id":532,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts\/524\/revisions\/532"}],"wp:attachment":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/media?parent=524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/categories?post=524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/tags?post=524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}