Qt4 Google MapView

July 12, 2009 | Filed Under Qt4 | No Comments

I’ve received a couple of requests about Google Maps and Qt4. Today I’ve written a simple Widget that allows you to interact with Google Maps and Google Geocoder. You can set Map Type (Roadmap, Satellite, Terrain and Hybrid), you can set your center Coordinate, add Markers, add Info Windows get the User Click Coordinates and other things that Google Maps allows to do.

Qt4 Google MapView

With few lines of code, you can interact with Google Maps, and below you can see how to do it. (Other methods and overloads are available, check the GKMapView.h in the Source Code packet, link is at the end of the post).

GKMapView mapView;

// Change the Default MapType (Roadmap, Satellite, Terrain, Hybrid)
mapView.setMapType(GKMapTypeSatellite);

// Use Geocoder to Get Location from Address or Viceversa.
// See the Signals locationFound, locationNotFound() and
// addressFound(), addressNotFound() to get your results.
mapView.locationFromAddress("San Mateo");
mapView.addressFromLocation(32.718834, -117.164);

// Add Marker With Info Window at Specified Address (or Location)
mapView.addMarkerWithWindow("Bedford MA Marker",
                            "<b>Bedford MA</b> Marker",
                            "Bedford MA");

// Add Info Window without Marker using Address or Coordinates
mapView.addInfoWindow("Hello from <b>San Mateo</b>", "San Mateo");
mapView.addInfoWindow("Hello from <b>San Diego</b>", 32.718834, -117.164);

// Change your Current Location
mapView.setLocation("Phoenix AZ");

The Source Code is available Here with a small example: Qt4 Google Map View Source Code.

Qt4 Geo IP Location

June 12, 2009 | Filed Under Qt4 | 2 Comments

In a time of Google Maps, Geo Location and other services like this… Here an example of Geo IP Location Service (http://www.hostip.info/) is really far from perfect, but it’s just an example.

Qt Geo IP Location

The sample uses QNetworkAccessManager to get the Geo Location of the IP, and Webkit to display the address on the Google Map.

The Source Code is available Here: Qt4 Geo IP Location Source Code.

Qt WebKit: Virtual Keyboard

March 16, 2009 | Filed Under Qt4 | 1 Comment

The Development of “Moko Touch” (My iPhone Clone for OpenMoko) goes on, And I’m writing a Mobile WebKit Browser. But The Phone need a Virtual Keyboard, and I Need to handle the WebKit forms. Internal WebKit/VirtualKeyboard of QtExtended doesn’t handle password forms… So, here an example of How to Add a Virtual Keyboard to your QWebView.

QWebKit Virtual Keyboard

Usage is easy, load your web page click on a Editable form and the keyboard will magically appear, click out of a form and keyboard will magically disappear :)

The code use a lot of JavaScript to handle the form click and focused out, and I don’t like it! So, If you’ve suggestions on how to implement it differently, post a comment or send me a mail! Thanks.

The Source Code is Available here: QtWebKit Virtual Keyboard Source Code.

WebKit: Google Maps

February 1, 2009 | Filed Under Cocoa | No Comments

Following the Google StreetView post, another example on How Cocoa Application can Interact with Google. Today the WebKit shows Google Maps.
Cocoa Google Maps - Aliso Viejo
Like iPhoto ‘09 you can select you Map Type (Terrain, Satellite, Hybrid) and you can Zoom In or Zoom Out using controls of your Application.
Cocoa Google Maps - Red Wood
You can Find the Source Code Here: Cocoa Google Maps.

WebKit: Google StreetView

January 17, 2009 | Filed Under Cocoa | 2 Comments

Last iPhoto ‘09 presented at MacWorld contains a couple of interesting Features: Faces and Places. Today, I’ve a little bit of free time to play with my Mac, and the topic is How to embed Google StreetView into a Cocoa Application.
Cocoa Streetview Cuppertino
The Solution is using WebKit and Google Maps API. We’ve a simple HTML file that contains StreetView “Canvas” and a couple of javascript methods that interact with GStreetviewPanorama Object.
Cocoa Streetview San Francisco
The Source Code is Available Here: Cocoa StreetView Source.

WebKit: Dynamic Content

December 6, 2008 | Filed Under Cocoa | No Comments

Today I’ve played a bit with WebKit. I Want do something like Cocoa VBox View and NSScrollView but with more flexibility. Below you can see the example result.

WebKit Dynamic Content

The interesting part of this example is How to manage WebKit content, and how to add something dynamically.

I use webView:decidePolicyForNavigationAction:request:frame:decisionListener: of WebPolicyDelegate Protocol to handle my custom requests, in this way…

- (void)webView:(WebView *)sender
    decidePolicyForNavigationAction:(NSDictionary *)actionInformation
   request:(NSURLRequest *)request frame:(WebFrame *)frame
   decisionListener:(id)listener
{
    if ([[[request URL] path] isEqualToString:@"PATH to Handle"]) {
        [listener ignore];
        // Handle Request
    } else {
         [listener use];
    }
}

…Then with a little bit of JavaScript I’ll set my dynamic content loaded from Database or somewhere else.

NSArray *args = [NSArray arrayWithObjects:@"Item1Content",
                                  @"Hi, I'm Test 1 Content", nil];
[[webKit windowScriptObject] callWebScriptMethod:@"fillElement"
                               withArguments:args];

The fillElement method is a simple JS function like this document.getElementById(elem).innerHTML = data;

Here you can find the Source Code.