Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Mobile Applications with TouchKit

The custom UI provider has to be added in a custom servlet class, which you need to define in the web.xml, as described in Section 22.4.3, “TouchKit Settings”. For example, as follows:

public class MyServlet extends TouchKitServlet {

private MyUIProvider uiProvider = new MyUIProvider();

@Override

protected void servletInitialized() throws ServletException { super.servletInitialized();

getService().addSessionInitListener( new SessionInitListener() {

@Override

public void sessionInit(SessionInitEvent event) throws ServiceException {

event.getSession().addUIProvider(uiProvider);

}

});

... other custom servlet settings ...

}

}

See the Vornitologist demo for a working example.

22.6.2. Geolocation

The geolocation feature in TouchKit allows receiving the geographical location from the mobile device. The browser will ask the user to confirm that the web site is allowed to get the location information. Tapping Share Location gives the permission. The browser will give the position acquired by GPS, cellular positioning, or Wi-Fi positioning, as enabled in the device.

Geolocation is requested by calling the static Geolocator.detect() method. You need to provide a PositionCallback handler that is called when the device has an answer for your request. If the geolocation request succeeded, onSuccess() is called. Otherwise, e.g . if the user didn't allow sharing of his location, onFailure is called.The geolocation data is provided in a Position object.

Geolocator.detect(new PositionCallback() { public void onSuccess(Position position) {

double latitude = position.getLatitude(); double longitude = position.getLongitude(); double accuracy = position.getAccuracy();

...

}

public void onFailure(int errorCode) {

...

}

});

The position is given as degrees with fractions. The longitude is positive to East and negative to West of the Prime Meridian passing through Greenwich, following the convention for coordinate systems. The accuracy is given in meters. In addition to the above data, the following are also provided:

1.Altitude

2.Altitude accuracy

Geolocation

493

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]