Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 811987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:07:56+00:00 2026-05-15T01:07:56+00:00

I’m building a Qt app with Python where you can point and click at

  • 0

I’m building a Qt app with Python where you can point and click at a (google) map and get the coordinates of the location. The map is shown through a QWebView loading a simple HTML page and the user can create markers by clicking. Screenshot of the widget after clicking on the map.

However, I’m having trouble to retrieve the just-clicked location coordinates back to Qt (so that I can use them as variables — and, for example, show them in the QLineEdits on the topleft corner above, as current location of the marker).

This is the relevant part of the HTML file:

<script type="text/javascript">
var map;
function initialize() { 
    var local = new google.maps.LatLng(-23.4,-40.3);
    var myOptions = {
        zoom: 5,
        center: local,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    } 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    google.maps.event.addListener(map, 'rightclick', function(event) {
        placeMarker(event.latLng);
    });
}

function placeMarker(location) {
    var clickedLocation = new google.maps.LatLng(location);
    var marker = new google.maps.Marker({
        position: location,
        map: map
    });

    map.setCenter(location);
}

function dummyTxt() {
    return 'This works.';
}
</script>

I’ve been trying with evaluateJavaScript, but was not able to retrieve the coordinates. I tried to created a function to access the position with marker.getPosition(), but with no luck. The dummy below works though..

newplace = QWebView.page().mainFrame().evaluateJavaScript(QString('dummyTxt()'))

>>> print newplace.toString()
This works.

Any suggestions on how to get the coordinates back to Qt?

Edit:

Here is the code that worked for me:

def update_geo(self):
    # Capture coordinates of the last marker on the map.
    mark = self.map.page().mainFrame().evaluateJavaScript('document.getElementById("markerlocation").value').toString()
    # Convert string to list of floats, stripping parentheses.
    marker = str(mark).strip('()').split(', ')
    decimals = [float(c) for c in marker]

Full source in https://github.com/nelas/veliger/blob/master/veliger.py#L2374

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:07:57+00:00Added an answer on May 15, 2026 at 1:07 am

    I found a work around to make it work but I’m not pretty sure that it will be the right approach. Anyway, this is what I did:

    1. Create a hidden input in the body section of your html document to save the position data of the marker:

      <body>
          (...)
          <input id="locationData" type="hidden">
          (...)
      </body>
      
    2. In the javascript code, save the position of the marker in the hidden input every time it’s created:

      function placeMarker(location) {
          (...)
          document.getElementById("locationData").value = marker.position;
          (...)
      }
      
    3. In your Qt code, read the value of the hidden input with the instruction:

      webView->page()->mainFrame()->findFirstElement("#locationData").evaluateJavaScript("this.value").toString();
      

    I hope it helps!

    Source: http://opendocs.net/qt/4.6/webkit-formextractor.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.