×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    33

    Unhappy evaluateJavaScript function can be used for loading maps in qt widgets?

    I tried the c++ code from this example: http://wiki.forum.nokia.com/index.ph..._With_QWebView

    It compiled but didn't load the map or the marker. I am NOT trying to load the map on some website. In fact I am trying to load it in a Qt widget.

    This code connect(this,SIGNAL(reloadMap()), this,SLOT(loadCoordinates())); from that example never got called.

    Then when I tried to call the function loadCoordinates myself at the end of the constructor, nothing happened, no maps no markers.

    Is this problem related to evaluateJavaScript function?

    I am missing some point here, I think. I need help.

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    Are you sure that Google Maps API key is still valid?
    P.S. This is why error handling, which is completely missing in the wiki article, is so important.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    Thanks for responding, now I followed this page: http://code.google.com/apis/maps/signup.html
    This page at the end asks me to enter the name of the website! But I am not developing this on any website, so how should I get the key?

    I tried some random website name and got a random key, but that too doesn't work.

    Please help.

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    Try to debug the wiki example.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    but I don't know what is wrong where so what should I start debugging?
    The problem may be related to the api key also.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    When you start debugging you always know that something is wrong and don't know what exactly. Finding exact reason of defect is a content of a debugging process.

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    Code:
    void QGoogleMapView::geoCode(const QString& address)
    {
    	cout << "\ngeocode\n";
    	clearCoordinates();
        
    	QString requestStr
    (tr ("http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap"
    "&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318"
    "&markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284&sensor=false"));
    
    	QNetworkReply *h = manager->get (QNetworkRequest (requestStr));
    	
    	if (h == 0)
    	{
    		cout << "NO ERROR";
    	}
    	else
    	{
    		cout << dec << "ERROR" << h << hex;
    	}
    }
    This results in ERROR 0x6de9e0
    There is no specified error with this code.

    Any helps?

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    This was really funny. You've made my day!

    P. S. pointers are not error codes.
    Additional reading:
    http://en.wikipedia.org/wiki/Pointer_%28computing%29
    http://doc.qt.nokia.com/latest/qnetworkreply.html#error
    Last edited by divanov; 2011-05-26 at 11:16.

  9. #9
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    I realized my fault soon after posting that,
    Code:
    QString hh = 
    "http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap"
    "&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318"
    "&markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284&sensor=false";
    
    
    	QNetworkReply *h = manager->get (QNetworkRequest (QUrl (hh)));
    	
    	if (h->error() == 0)
    	{
    		cout << "NO ERROR";
    	}
    	else
    	{
    		cout << hex << "ERROR: " << h << dec;
    	}
    there are no errors in this part, and that's more frightening, cz. map is still not loading.

  10. #10
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    This is also wrong as network errors are asynchronous by their nature. You should check for error in slot connected to finished signal.

  11. #11
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    Also, a question: how to know which version of Google's API am I using? I have heard that version 3 api doesn't need key.

  12. #12
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    I checked the replyFinished slot:
    Code:
    QString     replyStr (reply->readAll());
    
    QStringList coordinateStrList = replyStr.split(",");
    
    cout << coordinateStrList.size();
    [/code]
    and the coordinateStrList is showing 4 and value is: "200,1,1.3520830,103.8198360"
    still noting is getting displayed!!

    What can be the cause?
    Last edited by Anisha Kaul; 2011-05-26 at 12:56.

  13. #13
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    Also, I haven't mentioned the Google API Key, since I don't have a webpage or a
    phone, I am doing this on my computer on a qt widget. Is that the reason the javascript code is not doing anything?

  14. #14
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    I have identified the problem this time. There is a flaw in the way I am passing the Javascript code to the evaluatejavascript func. of QWebView.

    Using Google maps's API, when I click a pushButton attached to the slot holding the below code

    this->page()->mainFrame()->evaluateJavaScript (QString ("Open(%1,2)").arg ( point.x ()).arg (point.y ()) );

    the map pertaining to the location in question gets displayed.

    Now if I want to add a marker to a particular coordinate, I do:

    this->page()->mainFrame()->evaluateJavaScript (QString ("addMarker (%1, %2)").arg (point.x ()).arg (point.y ()) );

    This code doesn't execute. Any ideas?

    Besides this, what is the way to add a user defined function to evaluateJavaScript for evaluation?

  15. #15
    Registered User
    Join Date
    May 2011
    Posts
    33

    Re: evaluateJavaScript function can be used for loading maps in qt widgets?

    Finally found the answer!

    Any Javascript function which has to be called from function evaluateJavaScript is supposed to defined in an html file read by the C++ source as shown below:

    Now instead of creating a new add marker function, I have added its code in the Open function defined below:

    Code:
    var map;
    
    function initialize()
    {
          if (GBrowserIsCompatible()) 
          {
                map = new GMap2(document.getElementById("map"));
                map.setCenter( new GLatLng(0,0),1 );
          }
        }
    
    function Open (x,y)
    {
        map.setCenter (new GLatLng(x,y), 13);
    
        var point = new GLatLng (x,y);
        map.addOverlay (new GMarker(point));
    }

Similar Threads

  1. Replies: 6
    Last Post: 2011-02-11, 14:18
  2. Can this sdk be used to create local content for nokia ovi maps?
    By colin.rodrigues in forum Nokia Asha Web Apps
    Replies: 9
    Last Post: 2011-01-10, 13:40
  3. Replies: 0
    Last Post: 2003-11-17, 01:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×