1

I am using webkit2gtk-4.0 in my Vala appication to display Google Maps. And I need to get marker coordinates on button click. How can I manage it?

I figured out how to run javascript using run_javascript(), but I can't understand hot to get the results of it.

serge1peshcoff
  • 4,342
  • 11
  • 45
  • 76

1 Answers1

0

Ordinarily you would need to use Vala's async functions to do this, I believe like so:

var result = yield webview.run_javascript(...);

This is equivalent to the C function webkit_web_view_run_javascript_finish().

Unfortunately you can't take the next step shown at that link in Vala, as you need to use the JavaScriptCore API to get at the return value and that API isn't available in Vala.

There are a couple of dirty tricks that you can resort to in this case. One such trick is setting the window title at the end of your Javascript script, and watching for notifications on the webview's title property in Vala.

However, you may be better off writing a small bit of code in C that you compile into your Vala application.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • Can you show how to write this part of code in C (or link to pages where I can learn about it)? Or how to use this "changing webview title"? I completely don't understand how to manage it. – serge1peshcoff Dec 21 '14 at 19:47
  • 1
    There's an example in C at the documentation page I linked to. Another example is [here](http://stackoverflow.com/questions/16885242/vala-gui-and-logic-in-c). To change the webview title, connect to the `notify::title` signal and run `document.title = "Some result";` at the end of your Javascript script. – ptomato Dec 22 '14 at 01:46