How to send data from JS to Java? [message #1848560] |
Tue, 07 December 2021 18:05  |
Eclipse User |
|
|
|
Hi,
I followed https://eclipsesource.com/blogs/2010/12/18/a-new-google-maps-widget-for-swt-and-rap/
, it works very well without using RemoteObject!
As "You simply call JavaScript from Java and vice versa!" stated on the article ,
I tried to send latitude/longitude data from GMap.js to GMap.java by adding the following code in GMap.js.
window.getCurrentPosition = function() {
navigator.geolocation.getCurrentPosition(position => {
const { latitude, longitude } = position.coords; // successfully get latitude/longitude
// pack data in JSON form.
var jsonStr = '{"latitude":' + latitude.toString() + ', ' + '"longitude":' + longitude.toString() + '}';
const jsonCenter = JSON.parse(jsonStr);
return jsonCenter; // send back to RAP
});
}
Calling the function above from GMap.java with no error, but cannot get the return value, always gets null on Java side.
How can I achieve that?
Thank you so much!
David
[Updated on: Sun, 16 January 2022 20:52] by Moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03693 seconds