Showing posts with label Google Earth. Show all posts
Showing posts with label Google Earth. Show all posts

Saturday, 9 June 2018

HouseScanner: Using Google Maps and JSON to get Travel Time

This post describes how to extract JSON data from Google Maps. I need that for estimating the travel time from a house to my work.

Google Maps offers an API for querying directions. For example, a bicycle ride from Staffanstorp to Lomma, both in Skåne, Sweden is queried like this:
http://maps.googleapis.com/maps/api/directions/json?origin=Storgatan+4%2C+Staffanstorp%2C+Sweden&destination=Centrumgatan+13%2C+Lomma%2C+Sweden&mode=bicycling

The resulting file contains some useful information:
The total travel time is associated with the "duration" tag. The directions are listed under the "steps" tag.

A Google Maps set of bicycle directions between Staffanstorp and Lomma.
In order to retreive the duration, a query is sent with the origin and end addresses on the form; "Storgatan 4, Staffanstorp, Sweden".

The duration is found by browsing through the JSON tree to the tag that I need.

In my particular case, I compare the bicycle time with the public transit time at three different occasions. The shortest time is returned.

Saturday, 2 June 2018

HouseScanner: Implementation

I used python for fetching house data.

The script prompts for a URL to a house at a real estate portal.
Once the user has provided that URL, the script will fetch the house ad and analyse it using regular expressions.

The script searches for information using Regular Expressions, and adds them to a list.

Information about the local taxes are fetched from another web page, where I use the information about the town to get the tax rate.

Once that file is analyzed, I have almost everything that I need. The remaining information is an estimate of the travel time from the house to my work and from the house to my wifes work. I'll use Google Maps API and json to get this information.

Using Google Maps in a web browser, it is possible to get directions and estimates for travel time:


The information about the directions is sent to the web browser as a JSON (JavaScript Object Notation) object. I'll discuss how to get that data in detail in the next blog post.

When the script has run, the collected data is both printed on the console and copied to the clipboard:
Date, Address, Town, Starting Price, (Taxation value not available in ad), Number of rooms, Yearly maintenance cost, Construction year, Local tax rate, Living area, Other area, Garden area, Travel time for me, Travel time for my wife.
I use a script to copy to the clipboard:


Thursday, 16 March 2017

TrafficControl: Adding QML Components Dynamically

To be useful, TrafficControl needs to present the stations on an interactive map. The program logic is currently implemented in C++ with some Qt Graphical User interfaces using model-view relations.

The original presentation of the stations and tracks, that were imported from a KML file.

A part of the user interface will be based on QML, that imports a map from OpenStreet maps. QML is a design language where one can add graphical elements easily. I will describe a simple QML demo program later and publish it on my github account. 

The challenge for me has been to add components in QML dynamically from C++, when stations or tracks are found. The placemarks below are from Google Earth/KML.

The yellow placemarks are representing stations.
The stations has been identified and their coordinate has been sent to the QML part of the program,

The stations has been identified by trafficControl and dynamically added as circles

Some of the next steps will be:
  • Modifying the different stations individually
  • Adding tracks
  • Adding trains
  • Showing status when hovering the mouse pointer over the items
  • Modifying the components regarding their statuses
  • Investigating model/view for QML map items

Thursday, 6 November 2014

TrafficControl: Looking into Javascript

The last weeks, I've spent time learning Javascript. It is very similar to C++ and, obviously, Java so the learning gap has been quite small.

I'm investigating if I can use Javascript for trafficControl, using Google Maps/Earth to handle the maps with kml files. Kml files contains the coordinates for the tracks and the stations.

As a first step, I created a Javascript that loaded a kml file to a Google Earth window and displayed that on a web page. This was quite easy with the help from Google Earth API. There, one can find some very helpful examples: https://developers.google.com/earth/


The next step was to make the Javascript analyse the coordinates in the kml file. This gave me some headache as the kml file needs to be loaded into the script itself, and this isn't allowed for web security reasons. I'll discuss that in the next post.

For web programming I can recommend http://www.w3schools.com/ with their excellent tutorials in Javascript, AJAX, JQuery, html and several other technologies. For demonstations of their code, they have a "Try it Yourself" feature, where it is possible to modify their examples and explore the code.