Last active
March 9, 2023 12:42
-
-
Save webfirmframework/2a4dd279b197ebcef9de872e83430f54 to your computer and use it in GitHub Desktop.
Sample code to get geolocation at server side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.webfirmframework.samplecode.component; | |
import com.webfirmframework.wffweb.tag.html.attribute.event.mouse.OnClick; | |
import com.webfirmframework.wffweb.tag.html.formsandinputs.Button; | |
import com.webfirmframework.wffweb.tag.html.stylesandsemantics.Div; | |
import com.webfirmframework.wffweb.tag.htmlwff.TagContent; | |
public class GetGeolocationExample extends Div { | |
public GetGeolocationExample() { | |
super(null); | |
develop(); | |
} | |
private void develop() { | |
// wffweb-12.x.x example | |
new Button(this, | |
new OnClick(""" | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(function(position) { | |
source.position = position; | |
action.perform(); | |
}); | |
} | |
return false;""", event -> { | |
final double latitude = (double) event.data().getValue("latitude"); | |
final double longitude = (double) event.data().getValue("longitude"); | |
System.out.println("latitude = " + latitude); | |
System.out.println("longitude = " + longitude); | |
return null; | |
}, "return {latitude: source.position.coords.latitude, longitude: source.position.coords.longitude};", | |
null)) | |
.give(TagContent::text, "Get geolocation"); | |
// wffweb-3.x.x example | |
// new Button(this, | |
// new OnClick(""" | |
// if (navigator.geolocation) { | |
// navigator.geolocation.getCurrentPosition(function(position) { | |
// source.position = position; | |
// action.perform(); | |
// }); | |
// } | |
// return false;""", (data, event) -> { | |
// | |
// final double latitude = (double) data.getValue("latitude"); | |
// final double longitude = (double) data.getValue("longitude"); | |
// | |
// System.out.println("latitude = " + latitude); | |
// System.out.println("longitude = " + longitude); | |
// return null; | |
// }, "return {latitude: source.position.coords.latitude, longitude: source.position.coords.longitude};", | |
// null)) | |
// .give(TagContent::text, "Get geolocation"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read what is new in wffweb 12
Convert HTML5 to webfirmframework Java/Kotlin Code