title: Retrieve position of a google maps v3 marker to Qt in a desktop app with QtWebKit
body: <p>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 <code>QWebView</code> loading a simple HTML page and the user can create markers by clicking. <a href="http://lh3.ggpht.com/_fwC09vRdEJ4/S_c1KlmdJeI/AAAAAAAAA1c/hpYvF5jmkH0/geo_shot.png" rel="nofollow noreferrer">Screenshot</a> of the widget after clicking on the map.</p>
  
  <p>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 <code>QLineEdit</code>s on the topleft corner above, as current location of the marker).</p>
  
  <p>This is the relevant part of the HTML file:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  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.';
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I've been trying with <code>evaluateJavaScript</code>, but was not able to retrieve the coordinates. I tried to created a function to access the position with <code>marker.getPosition()</code>, but with no luck. The dummy below works though..</p>
  
  <pre><code>newplace = QWebView.page().mainFrame().evaluateJavaScript(QString('dummyTxt()'))
  
  &gt;&gt;&gt; print newplace.toString()
  This works.
  </code></pre>
  
  <p>Any suggestions on how to get the coordinates back to Qt?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Here is the code that worked for me:</p>
  
  <pre><code>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]
  </code></pre>
  
  <p>Full source in <a href="https://github.com/nelas/veliger/blob/master/veliger.py#L2374" rel="nofollow noreferrer">https://github.com/nelas/veliger/blob/master/veliger.py#L2374</a></p>