Java Geolocation API Demo
package org.apidesign.html.location;

import net.java.html.geo.OnLocation;
import net.java.html.geo.Position;
import net.java.html.json.ComputedProperty;
import net.java.html.json.Function;
import net.java.html.json.Model;
import net.java.html.json.Property;

/** Defines model and operations to deal with Geolocation API.
 *
 * @author Jaroslav Tulach <jtulach@apidesign.org>
 */

//
// properties with setters and getters in class LocationModel
//

@Model(className = "LocationModel", properties = {
    @Property(name = "latitude", type = double.class),
    @Property(name = "longitude", type = double.class),
    @Property(name = "message", type = String.class)
})
final class LocationController {
    //
    // Derived property and callback function in LocationModel
    //
    
    @Function static void findLocation(LocationModel model) {
        // when clicked, initializes single location query
        LocateMeHandle.createQuery(new LocationController(model)).start();
    }
    
    @ComputedProperty static String url(double latitude, double longitude) {
//        return "http://m.mapy.cz/map?&t=1&z=12&y=" + latitude + "&x=" + longitude;
        return "http://www.mapy.cz/#!x=" + longitude + "&y=" + latitude + "&z=11&l=16";
    }
    
    @Function static void findPraha(LocationModel model) {
        // find fixed point
        model.setLatitude(50.1);
        model.setLongitude(14.45);
    }
    
    //
    // handling of location query and errors
    //
    
    private final LocationModel location;
    private LocationController(LocationModel l) {
        this.location = l;
    }
    
    @OnLocation(onError = "error") void locateMe(Position p) {
        // modify the location with newly obtained position
        location.setLatitude(p.getCoords().getLatitude());
        location.setLongitude(p.getCoords().getLongitude());
    }
    
    void error(Exception ex) {
        location.setMessage(ex.getMessage());
    }
    
    //
    // Initialize to my home village
    //
    
    static {
        LocationModel loc = new LocationModel();
        loc.setLongitude(16.0075239);
        loc.setLatitude(50.5622514);
        loc.setMessage("OK");
        loc.applyBindings();
    }
}