Archive for the ‘Web Service’ Category:
How to use W3C Geolocation API in Mobile (Basic)
Previously Geocoding from mobile web (or ‘ordinary’ web application) is achieved through Google Gears (as pre-installed in Android 1.5+). However the W3C Geolocation API Specification has render Google Gears obsolete as newer browsers has these functionality built-in (including mobile browser).
How to include Geolocation API in a Web Page?
The most basic code that you started is listed below, the code below tests if the browser have built-in support for geolocation. If it does have geolocation support, it will call either one of the callback “successCallback” or “errorCallback”.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
} else {
error('Sorry, your browser does not support geolocation');
}
“successCallback” is call whenever the API call is successful. You need to create a function for “successCallback”, as shown in the example below:
function successCallback(pos) {
var lat, long;
lat = pos.coords.latitude ;
long = pos.coords.longitude;
var element = '<p><a href="http://maps.google.com/maps?q='+lat+','+long+'&hl=en">Latitude: ' +lat+ ' Long: ' + long + '</a></p>';
alert(lat +','+long);
$('body').prepend(element);
The function will return the latitude and longitude data and stores it in ‘lat’ and ‘long’ variable, which is then displayed to the screen.
Get the latest iftar (breaking fast) time with TimeToBuka.com
TimeToBuka.com is a mobile web application that lets you check the latest iftar time (breaking fast time – for Muslim during Ramadan month). The application detects the current user location (using Google Geocoding API) and displays the time for Iftar and Imsak for the current location.
However, the application currently only supports Malaysian and Singapore users only. But you can help the author ( Nazrul Kamaruddin ) to add support for more countries by providing him with the appropriate data.
The application is tested and confirmed to work in Android 1.6+, 2.x and iPhone
a simple Click-A-Tell SendSMS HTTP POST API library
Click-a-tell is a simple web service that allows you to integrate sms sending capability into your web application. Its simplicity and wide range of API available is very attractive to small to medium web application developers. Among the API supported by Clickatell are :
- HTTP POST
- HTTP GET
- FTP API
- SOAP
- EMAIL-to-SMS
- COM Object
Clickatell website offers examples of how to use their API in several programming language including but not limited to : VB.net, PHP, ASP, ASP.NET,PERL, Python, Coldfusion, etc.
However I found that the example written for PHP is a little bit outdated and it uses the file() function to initiate HTTP GET request which is generally restricted on webservers as it pose a huge security risk. The other Clickatell class found through PHPClasses website are either too cumbersome for my project or supported other protocol than I intended to use.
As a result I wrote my own Clickatell SMS (clickatell_sendsms_0.5.zip) class specifically for my own use.
Here are a sample code using the SendSMS 0.5 class
<?php
require('SendSMS.php');
$sendsms = new SendSMS("username","password","HTTP POST API key");
/* if the login return 0, means that login failed, you cant send sms after this */
if ( ($sendsms->login()) == 0 ) {
die( "failed");
}
/*other wise, you can send sms using the simple send() call*/
$sendsms->send("0132073011","testing send sms - camna? boleh dpt ? - mr hafiz");
?>
You can download the clickatell_sendsms_0.5.zip”>SendSMS 0.5 PHP class from this website, note that the class is licensed under the terms of the GNU General Public License version 2, and the class is only meant to be use with Click-A-Tell HTTP POST API.
The class can also be use with the libcurlemu library whenever applicable.
TinyGeo-coder : A cool free geocoding/reverse geocoding service
I was searching for a free and easy to use geocoding web service over the internet for my experiment involving Location Based Service (LBS). Then suddenly i came accross tinygeocoder, a web service which really suits my need.
tinygeocoder services that caught my eye :
- geocoding – you can feed it with name of place like “San Francisco, CA” and it will return result in latitude and longitude pair “(37.775196,-122.419204)”
- reverse geocoding – feed it with a coordinate, and the service will return you the name of the corresponding place.
Personally I like the “reverse geocoding” functionality more as it would be handy for my LBS project. Keep an eye for this blog as I’ll be posting JavaME JSR-179 (Location API) codes which utilizes tinygeocoder services.
p/s: If you find tinygeoder helpful, consider making donations to them.
Tags: api, codes, example, geo coding, geocoder, geocoding, gps, lbs, location, location-api, maps, mobile, REST, web, Web Service
