tag:blogger.com,1999:blog-82605473697030709772024-03-05T03:24:02.839-05:00Datamoil blog. Undocumented solutions.I write solutions to the problems I can't find much about elsewhere on the Web, also some code/script snippets that are absolutely awesome and make my life easier. Will be glad if someone finds these posts interesting and helpful!Unknownnoreply@blogger.comBlogger14125tag:blogger.com,1999:blog-8260547369703070977.post-23361790037917017752011-09-23T10:21:00.003-04:002011-09-25T05:35:38.427-04:00Calculate distance between two points with MySQL<div dir="ltr" style="text-align: left;" trbidi="on">
This function here is the right one. It returns pretty same results as the Google Maps distance, which leads me to believe that it's kind of correct.<br />
<br />
<script src="https://gist.github.com/1237415.js">
</script>
<br />
I've seen a lot of ready solutions online for the same input/output/platform combination (i.e. WGS84 degrees input/output on MySQL), but all of them used some other formula (at the end multiplying by 1.1515) that was producing some results that never worked for me.<br />
<br />
On the other hand the following formula returns results identical with what Google Maps returns.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJKxjCN5f73vf8CAVN44av-yMrw2h8Ti_VDgy2yCYF9llycgo-nJ-BbWbN1DSHSYurGH7Rts_J06iptoiTJvyDuUEH8kX62l1tEzYh0jh9JfOGt763N8wjGjdsyjkJhThUE7IrTnEJD0kK/s1600/execution+output.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJKxjCN5f73vf8CAVN44av-yMrw2h8Ti_VDgy2yCYF9llycgo-nJ-BbWbN1DSHSYurGH7Rts_J06iptoiTJvyDuUEH8kX62l1tEzYh0jh9JfOGt763N8wjGjdsyjkJhThUE7IrTnEJD0kK/s1600/execution+output.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">My function output</td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="clear: right; float: left; margin-bottom: 1em; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCQC8P5z3Q9aSrkjDW29j_x7wTtA2IfKF_Pz85cB_RVIhHsbqhUaKjKBqrsGB2LY54o40P3puIR9dM0XBhY0-3nZRBE4pNM5HgA2xIbE-Ap0cs0eEK1mw1P84GExChNQJnB0_ziXk4mlZH/s1600/cross+check.png" imageanchor="1" style="margin-left: auto; margin-right: auto;">
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCQC8P5z3Q9aSrkjDW29j_x7wTtA2IfKF_Pz85cB_RVIhHsbqhUaKjKBqrsGB2LY54o40P3puIR9dM0XBhY0-3nZRBE4pNM5HgA2xIbE-Ap0cs0eEK1mw1P84GExChNQJnB0_ziXk4mlZH/s1600/cross+check.png" /></a>
</td></tr>
<tr><td class="tr-caption" style="text-align: center;">Cross check</td></tr>
<tr><td><div>
Apparently there's some issue with the bearing and that's why the result is still not precisely accurate, but it's much closer than the other methods' outputs I've tried before.
</div>
</td></tr>
</tbody></table>
<br />
<div>
<br /></div>
</div>
Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-8260547369703070977.post-51676973234985066062011-06-07T04:26:00.001-04:002011-06-07T04:28:10.648-04:00Offline tiled layer with ArcGIS for Android<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">On the </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">official </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">ArcGIS mobile blog they have described <a href="http://blogs.esri.com/Dev/blogs/mobilecentral/archive/2010/12/13/Developing-a-custom-tiled-layer.aspx">how to create an offline tiled layer for iOS</a>, but not a word about Android (probably because it's still in beta, thing might change and it doesn't gain any publicity anyway). </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The idea was taken from this blog: if not for that, I would've not even attempted to look into this direction. </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">So thank God for a custom hack!</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">My first attempt for offline tiles was to create a local tile server and in the </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">ArcGISTiledMapServiceLayer</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> as a URL supply something with </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">localhost</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> in it. It totally worked, but there were two issues that forced me to look for another solution. Number one was technical: as soon as the connection was down (e.g. Airplane mode turned on) the tiles would just stop to download (even though their physical location was on the same SD card the application was installed on!); the second issue was mental: just for knowing that the files stored locally had to take a trip to the moon before being rendered (let alone maintaining a whole process of a local map server), caused an allergy and made me invest some time into research.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">So here we go with offline tiled layer. Easier than easy, with a very little code, but totally impossible to find out how to make it! At least at the current version of ArcGIS for Android all the interesting stuff regarding custom tiled layers is undocumented.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Here's the implementation of the custom tiled layer:</span><br />
<script src="https://gist.github.com/1011854.js">
</script></div><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Here's a usage example:</span><br />
<script src="https://gist.github.com/1011865.js">
</script><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Now about the filesystem. In the usage example I have set some values to the </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OfflineTiledLayer </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">constructor and these represent the directory structure. First off, I didn't use the cache created by ArcGIS. I mentioned in the beginning of the post that earlier I had implemented a local map server, that's why the file paths reflect the ones used by the online map servers. For instance, the absolute path of the tile at <i>zoom level 3/row 44/column 65</i> looks like </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">/mnt/sdcard/services/RoadMapsWebMercator101010/MapServer/tile/3/44/65</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">. I guess it's not hard at all to modify my class to use the HEX paths of the cache created by ArcGIS.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Finally, a couple words about the map server specification. That paramter </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">index.html</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> of the </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OfflineTiledLayer </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">constructor represents this. Again, I named it <i>index.html</i> to support the local map server </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">implemented earlier</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">, but in fact it contains what an online map server outputs by clicking on the link "</span><i style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">REST</i><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">" on the bottom of the MapServer description page of the ArcGIS server (the address looks something like </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><your map="" server="" url=""></your></span><your map="" server="" url=""><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">/MapServer?f=json&pretty=true</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">). </span></your><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><your map="" server="" url=""> <br />
And that's totally it. Hope it helps!</your></span></div>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-8260547369703070977.post-645209066793449492011-05-06T11:43:00.004-04:002011-05-19T04:29:35.902-04:00Cloudmade routing on OSMDroid<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Another mystery without much relevant results on Google search that turned out to be quite an easy task.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Cloudmade seems to make a lot of effort to provide developers with a lot of <a href="http://cloudmade.com/products">mapping features</a>, and as I haven't found anywhere on the site how to pay them, I take it that their service is free. It seems also that they use OpenStreetMaps as a back-end, therefore (here goes the disclaimer) <b>ROUTING IS NOT VERY ACCURATE</b>. At least not yet, but it's being improved a lot; I've added a Starbucks shop about a month ago, and now it's visible on the map!</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Among other services Cloudmade offers <a href="http://developers.cloudmade.com/wiki/routing-http-api/Documentation">Routing HTTP API</a>, which seems to be a breeze for use within HTML code (they support JSONP-style callback for script injection to go around cross-origin resource sharing restrictions). This is the one to be used in the open map view with open map controller, because Google Maps doesn't allow routing anywhere outside their domain (Google even removed routing API from Android right after the very first release!).</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">My implementation of the </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">BlueLine </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">does everything from requesting directions, all the way to drawing them on the map.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Create a </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">class </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">extending </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">PathOverlay </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">with the following code:</span><br />
<script src="https://gist.github.com/959118.js">
</script><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The Cloudmade API key goes into the manifest file within the application element like here</span><br />
<script src="https://gist.github.com/959151.js">
</script><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">And that's pretty much it. It's very easy to make it work now with the application:</span><br />
<script src="https://gist.github.com/959200.js">
</script><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirWL2fSAB2KS8Kg65jYZQuNySuF06SYO9QBFY-1X-ga6huf7Abdq6u_IaOCvQxrP6Ai5RtAz8T4k_f7DA4XYB71PxOOwxQkxWFPWRa718pVJm80ZVkiqM2WTRug-NK_XUsLHCImRbGUJzV/s1600/blueline.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="221" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirWL2fSAB2KS8Kg65jYZQuNySuF06SYO9QBFY-1X-ga6huf7Abdq6u_IaOCvQxrP6Ai5RtAz8T4k_f7DA4XYB71PxOOwxQkxWFPWRa718pVJm80ZVkiqM2WTRug-NK_XUsLHCImRbGUJzV/s320/blueline.png" width="320" /></a></div><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">That's really it! Hope it helps.</span></div>Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-8260547369703070977.post-40083093127166858252011-05-05T06:08:00.014-04:002011-05-19T03:15:44.444-04:00Offline Google Maps for Android<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">This took me a while to figure out as I couldn't find any tutorial, but it's fairly easy after all.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The map container of my choice is <a href="http://code.google.com/p/osmdroid/">OSMDroid</a>, which is a great (and open source!) replacement for Google Maps container.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Resolve the </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">MapView </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">and set tile provider as follows</span><br />
<script src="https://gist.github.com/956756.js">
</script><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">It basically defines a new </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OnlineTileSourceBase </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">with:</span><br />
<ul style="text-align: left;"><li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>name </i>"Google Maps" (this is an important bit, as it will be used to lookup the directory with offline tiles)</span></li>
<li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>resource id</i> "unknown" (I also downloaded OSMDroid source code, added a value "google" to the </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">ResourceProxy.string </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">enum and used that instead)</span></li>
<li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>minimum zoom level</i> 1</span></li>
<li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>maximum zoom level</i> 20</span></li>
<li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>tile size</i> 256 pixels</span></li>
<li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>tile file extension ".</i>png"</span></li>
<li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>tile base url</i></span></li>
<li><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">finally inside the overriden method </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">getTileURLString </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">it describes how to build a URL to get a tile for specific location and zoom level</span></li>
</ul><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">OK, now the controller supports Google Maps and if </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">setUseDataConnection</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> was set to </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">true </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">it would already show everything and would work fine with Google Maps. But the mission is to make it work offline. </span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The best tool to export the tiles for an area is <a href="http://mobac.sourceforge.net/index.html">Mobile Atlas Creator</a> (version up to 1.8, they removed Google Maps from 1.9). Export an area with map source set to <i>Google Maps</i> in desired zoom levels in <i>Osmdroid ZIP</i> format (it's going to take a while). Put the output ZIP file into the <i>/sdcard/osmdroid/Google Maps</i> directory (if it doesn't exist, create it; the name has to be the same as the first parameter in the OnlineTileSourceBase constructor). Again, as I downloaded the source code for OSMDroid, I changed some values in the </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> class (such as </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OSMDROID_PATH</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> to put the tiles in my directory instead of /sdcard/osmdroid).</span></span><br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Start up the application, now it should show offline tiles. Notice that now, if the SD card is unmounted, the controller will appear empty.</span></div><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">But the story doesn't end here. As the <a href="http://code.google.com/apis/maps/terms.html">Google Maps terms of use</a> (10.1.3.b) state:</span><br />
<blockquote><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>No Pre-Fetching, Caching, or Storage of Content. <b>You must not pre-fetch, cache, or store</b> any Content, <b>except that you may store</b>: (i) <b>limited amounts</b> of Content for the purpose of improving the performance of your Maps API Implementation if you do so <b>temporarily</b>, securely, and in a manner that does not permit use of the Content outside of the Service; and (ii) any content identifier or key that the Maps APIs Documentation specifically permits you to store. For example, you must not use the Content to create an independent database of “places.”</i></span></blockquote><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">So it sounds like an application is quite limited to use offline Google Maps tiles. </span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Nonetheless, it seems they don't disallow to temporarily cache the tiles and work in online mode (of course then one also needs to store the tiles securely). To achieve this, unzip the ZIP file with extracted map area into the location <i>/sdcard/osmdroid/Google Maps/tiles </i>(or whatever is the location specified in </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OpenStreetMapTileProviderConstants.</span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OSMDROID_PATH</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">), then set </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">mapView.setUseDataConnection</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">(</span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">true)</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">. The default cache expiry period is not very long, so I also altered it in the source code by setting the values of </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OpenStreetMapTileProviderConstants.TILE_EXPIRY_TIME_MILLISECONDS</span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">and </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">to (</span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">1000 * 60 * 60 * 24 * 365 * 10) </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">(that's 10 years) . This</span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> will make OSMDroid to use </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">pre-fetched </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">tiles for areas where available, but for the rest of the world it will download new tiles.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"></span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">That's it. Hope it helps.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><b>UPDATE </b>As stated in the comments, you need the <a href="https://docs.google.com/leaf?id=0B3-h2Sh7HmRqMjBjOTIwYjEtNTA4Yy00Zjc5LWExMTYtYTUxNGY0NGRiZDBh&hl=en&authkey=CO-4kLQE">Mobile Atlas Creator version 1.8</a> (I see they removed all versions prior to 1.9 from sourceforge). The other tool capable of fetching tiles is "OsmAnd Map Creator" (I see they deprecated it too, still it's available for <a href="http://goo.gl/B4V1X">download</a>), but I'm not sure what the </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">output </span><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">directories look like, so one would have to adjust it manually to the structure OSMDroid controller expects.</span></div>Unknownnoreply@blogger.com10tag:blogger.com,1999:blog-8260547369703070977.post-61047502002201941512011-04-29T08:57:00.013-04:002011-05-05T06:09:48.126-04:00Android universal Intent to start a "navigation activity"<div dir="ltr" style="text-align: left;" trbidi="on">The mission is what the title says. It was quite hard to define the problem to search for a solution. I ended up asking for help at <a href="http://stackoverflow.com/questions/5801684/intent-to-start-a-navigation-activity/">StackOverflow</a> and as I was suggested, I implemented a way to list some known apps and let the user select a preferred nav app.<br />
<br />
So, let's say, somewhere on Activity there's a button, which on click is supposed to call the Navigation application. The way I did it, on tap, the activity shows a custom dialog letting the user select one of the known applications or prompt Android to find suitable activities implicitly.<br />
<br />
Here's the source code of the payload of the main method invoked from the OnClickListener - showNavigation():<br />
<script src="https://gist.github.com/948236.js">
</script><br />
<br />
Here are few utils needed only to follow up the last call in the showNavigation() method - showTableDialog():<br />
<script src="https://gist.github.com/948238.js">
</script><br />
<br />
These are the resource files:<br />
* this goes to /res/values/themes.xml<br />
<script src="https://gist.github.com/948240.js">
</script><br />
* this goes to /res/values/styles.xml<br />
<script src="https://gist.github.com/948243.js">
</script><br />
* this goes to /res/layout/table_dialog.xml<br />
<script src="https://gist.github.com/948245.js">
</script><br />
* this goes to /res/drawable as menu_gps.png<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjtJASPScu6pqX59cCBd8pSWSO6gL-NUrmDBRrpFbf5nNc0mn9USP7SH8ZVJo7Mw59tcLjFOm3hQ9CKFc5m53aoha9-TZXUqMQFJ6s8Y4alW5Fb67DU_fkqFjFODLIy_R-eNXCFtNNTDky/s1600/menu_gps.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 0em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjtJASPScu6pqX59cCBd8pSWSO6gL-NUrmDBRrpFbf5nNc0mn9USP7SH8ZVJo7Mw59tcLjFOm3hQ9CKFc5m53aoha9-TZXUqMQFJ6s8Y4alW5Fb67DU_fkqFjFODLIy_R-eNXCFtNNTDky/s1600/menu_gps.png" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
And here is the result dialog you are supposed to see:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvMgghbvFGeTlXZBZ7lacC0o7gV6rOKMoHX7JtNa9ry4NbXbkDkEZoW9ltibsEz_sRW1UV2IxWDAEahIRD45gE4Y2b8Nf9REGkux2UkAwj5Gd-igLqHFFm2rmgNOgSK0H5jHZq1C0d4NRV/s1600/navigator_select.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvMgghbvFGeTlXZBZ7lacC0o7gV6rOKMoHX7JtNa9ry4NbXbkDkEZoW9ltibsEz_sRW1UV2IxWDAEahIRD45gE4Y2b8Nf9REGkux2UkAwj5Gd-igLqHFFm2rmgNOgSK0H5jHZq1C0d4NRV/s1600/navigator_select.png" /></a></div>On click on each row it will start up the respective activity.<br />
That's it, I hope it helps!</div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-8260547369703070977.post-22212136728023891612010-05-03T15:30:00.005-04:002011-04-29T04:14:37.798-04:00Accumulative sorting in ADF 10g tablesJust what the title says.<br />
<br />
In an application there were a few tables filled with results of some queries. I haven’t yet figured out why, but it was of a high importance to the client that all the tables had accumulative sorting (like the order by clause in SQL). This requirement took me a while to figure out how to implement, whilst the solution was quite elegant and pretty small to write it here.<br />
<br />
So, there’s a table with results of a search (the query really doesn't matter as the entire sorting solution will be implemented in the view layer)<br />
<script src="https://gist.github.com/948033.js"> </script><br />
The whole trick is to set <b>sortListener=”#{CustomersBean.onSort}”</b> for the table. The backing code for this sortListener is found in the backing bean named CustomerBean.<br />
<script src="https://gist.github.com/948035.js"> </script><br />
And that’s pretty much it. The table is now sortable accumulatively: you can hit customerid first, then name, then surname etc. the resulting table will look similarly to what produces SQL clause order by customerid, name, surname, etc.<br />
Hope this helps.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8260547369703070977.post-25188992895233290782010-05-03T15:27:00.011-04:002011-06-02T04:52:33.736-04:00“javax.faces.convert.ConverterException: Unsupported Model Type” in ADF 10g for selectManyCheckbox<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">There’s a mess with the selectManyCheckbox bindings: for both initial list items and selected items. ADF itself doesn’t support direct binding to a ViewObject, and that’s why, as Frank Nimphius said,</span><br />
<blockquote><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">…you would need to use a managed bean to dispatch between the ADF binding layer and the multi select component.</span></blockquote><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Maybe it’s just me, but it took me a while to figure out how exactly to do it.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">First off, the managed bean. It should contain fields with accessors for two lists: the initial options and the selected items.</span><br />
<script src="https://gist.github.com/948028.js">
</script><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The initialListItems will be bound to the multi-selection items element. Whilst the selectedItems list will contain the selected items from the initial list. The important thing is the datatype for the latter – a java.util.List! In fact it’s what provokes the “Unsupported Model Type” exception. This datatype hassle was actually the part that took me a real while to get it, I tried primitive array, ArrayList of String’s, Object’s and what not!</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Now the only thing left is to bind both lists to the multi-selection component.</span><br />
<script src="https://gist.github.com/948030.js">
</script><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">No more exceptions. That's it, hope it helps!</span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8260547369703070977.post-43927501200700024942010-05-03T15:26:00.008-04:002011-04-29T04:10:03.302-04:00How to add showPopupBehavior to an ADF Rich Faces table columnI didn’t see the answer to that anywhere in the manual, so I had to experiment myself. Ofc I sort of figured out how to do it pretty easily. Still this tutorial can save someone’s time, I hope.<br />
So, basically, what one can do to pop a dialog with ADF Rich Faces, is 2 simple steps:<br />
1. Define a popup with a dialog in it<br />
2. Set showPopupBehavior of the link or button to point to that popup.<br />
<script src="https://gist.github.com/948016.js"> </script><br />
Pretty simple, isn’t it? Now the question is how to achieve the same behavior per row in a table. If we set the same showPopupBehavior popupId to a command object found in a column, it won’t work and JDeveloper will mark it as an erroneous syntax (“Reference Id confirmDelete not found”). Well, the trick is that the popup should be defined inside the column, and that’s actually it. Here’s a code snippet.<br />
<script src="https://gist.github.com/948023.js"> </script><br />
The method in the backing bean looks like:<br />
<script src="https://gist.github.com/948025.js"> </script><br />
The navigation part is intended to refresh the page (there’s a global rule in the faces-config.xml for outcome “scheduler” to navigate to this page), because dialog handler doesn’t do it automatically with JSF controller.<br />
Hope this helps!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8260547369703070977.post-74422333831960300712010-05-03T15:26:00.007-04:002011-04-29T04:03:49.520-04:00How to make the Oracle Application Server 10g run as a Windows serviceA problem that recently has been bugging the project I’m currently working on, was to make the Oracle Application Server 10g run as a service, so that it would be available without a user logging in and starting it up manually. We solved it with the use of an open source middleware project called JavaService, a pretty neat tool. Find below how.<br />
<br />
<b>Requirements</b>:<br />
Windows machine (the guide was tested with a vanilla Windows 2003 server installation)<br />
Oracle Application Server 10g<br />
The latest version (today 2.0.10) of <a href="http://forge.ow2.org/project/showfiles.php?group_id=137">JavaService</a><br />
<br />
<b>Actions</b>:<br />
<br />
Let’s say JavaService is unzipped to C:\JavaService-2.0.10<br />
Then from the JavaService-2.0.10 directory execute: <br />
<script src="https://gist.github.com/948014.js"> </script><br />
Now the service OAS can be found among other services.<br />
<br />
Should be also mentioned, that the Application Server better be stopped by the time you attempt to start the service.<br />
<br />
Hope this helps.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8260547369703070977.post-77098039167399813402010-05-03T15:23:00.014-04:002011-06-02T05:00:45.118-04:00Global validation for a Date input field in ADF 10<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Say you have a table with a date column and you have created a view accessing it. Now try to insert an abnormal date into the dateInput field on the page (something like 1/1/111111111), commit the changes, check the value in the DB and you’ll get what I’m talking about here. I had queried a question on the OTN forum regarding this and the only answer I got was from Frank Nimphius to</span><br />
<blockquote><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">configure a value change listener on the date field and verify that the provided value is valid, If not call FacesContext.renderResponse to ignore the request</span></blockquote><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">this is a solution, but well, it requires more or less to apply it to each dateInput field on every single page. The other way around that I finally used, was to override the EntityImpl setAttributeInternal method like the following:</span><br />
<script src="https://gist.github.com/1004140.js">
</script><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">which actually just checks that the Date attribute provided is of a logical range.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">This method has to be part of a class extending oracle.jbo.server.EntityImpl and obviously the entity implementation for that table with a date column must extend the new EntityImpl class.</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">That's it. Hope this helps!</span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8260547369703070977.post-16021969694521148792010-05-03T15:23:00.011-04:002011-06-02T04:56:34.968-04:00Oracle database schema data removal<div dir="ltr" style="text-align: left;" trbidi="on">In my previous post I mentioned a script I used to drop everything from the schema, and I thought it could come handy to someone, hence here it is:<br />
<script src="https://gist.github.com/948006.js">
</script><br />
This script has been extensively tested on Oracle 10g for all kind of editions and seems to work awesomely!<br />
Beware, this <b>WILL REMOVE EVERYTHING FROM THE DATABASE SCHEMA FOR USER YOU HAVE CONNECTED AS</b>; that is if you connect as sysdba, it will most likely make the database useless.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8260547369703070977.post-79299692946942911912010-05-03T15:23:00.010-04:002011-04-29T03:58:20.296-04:00Clear an iterator in ADF 10gThe mission is to empty out an iterator without setting its Refresh attribute to “never” and consequentially executing it manually. What I ended up doing, when I needed this once, was adding a parameter to the query WHERE clause (something like “and 1 = nvl(:param, 1)”) and invoking it with a zero when I needed it empty. Apparently there is an easier way.<br />
Say the iterator to clear is defined in the pageDef as:<br />
<script src="https://gist.github.com/948008.js"> </script><br />
Then the code in the backing bean would look like:<br />
<script src="https://gist.github.com/948009.js"> </script><br />
That’s it. Hope this helps!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8260547369703070977.post-74133816068484999852010-05-03T15:22:00.000-04:002010-05-03T15:22:24.752-04:00Service management in WindowsGo to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services in Registy Editor (regedit.exe under WINDOWS\system32), there lookup the service by name. Properties appear on the right of the tree.<br />
One property that can be surely needed at some point is the location of the executable of a service. That’s the property ImagePath.<br />
Whoever has set up an Oracle Database instance knows what I’m talking about here The story behind that, is that I made the mistake to run the script which drops everything from my scheme, whilst I had connected as sysdba Yeah, I know.. stupid. Well, not the first time Anyways, the thing is that during second set up, Oracle DB seems to highly dislike the previous instance and does not alter all the services correctly (oh, I just hope that it wasn’t left intentionally, because that would mean, the developers aren’t human beings). E.g. the OracleCSService (something to do with clustering) doesn’t shut down correctly and consequentially during the second set up the path doesn’t change. Here I had to change the ImagePath for it at the location HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OracleCSService. As simple as that.<br />
The truth be told, I still haven’t figured out how to properly set up a fresh instance after removing the previous. Sounds like a story for another post.<br />
<br />
P.S. After quite a research I found a great post about a complete removal of the previous installation. Find it <a href="http://aricsblog.blogspot.com/2005/08/uninstalling-oracle-10g-manually-from.html">here</a>. I tried the method described like a hundred times already and it seems to work perfectly.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-8260547369703070977.post-35510667363367639172010-05-03T15:19:00.008-04:002011-04-29T03:52:05.774-04:00Silently print Jasper reportsI’ve recently come across an issue with the project I’m working on regarding what the title says. The thing is that the users didn’t want to see any kind of dialogs prompting to print the report. Well, it was pretty easy after all and the class I wrote follows. <br />
<script src="https://gist.github.com/948004.js"> </script><br />
And here’s a usage sample:<br />
<script src="https://gist.github.com/948000.js"> </script><br />
Hope this helps anyone.Unknownnoreply@blogger.com2