Namespaces
Variants
Actions
Revision as of 08:22, 29 June 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Getting routes from Google Maps for JavaScript

Jump to: navigation, search
Archived.png
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

MultiMediaTile.png
Article Metadata

Code Example
Source file: Media:Rout libs.zip

Tested with
Devices(s): 3rd Edition devices

Compatibility
Platform(s): Python for s60

Article
Keywords: Python, LBS, Routs, Google Maps
Created: diegodobelo (14/03/2009)
Last edited: hamishwillee (29 Jun 2012)


Contents

Overview

Location Based Services are one of the most used services in mobile application today. Sometime, routs are needed to determine how to go to a location more easily. This tutorial teaches how to get routs from Google Maps.

Preconditions

This example needs import some modules wich can be encountered File:Rout libs.zip. It also needs internet connection.


Source file

In this example we will get routs from Campina Grande to Joao Pessoa, both cities in Brazil. To get routs for other locations, just alter START_LOCATION and END_LOCATION string constants.

import urllib
from html_parser import *
 
START_LOCATION = "campina grande"
END_LOCATION = "joao pessoa"
 
def parser_html(start,end):
rout_link = "http://maps.google.com/maps?dc=gorganic&eosr=on&source= \
mobileproducts&daddr="
+ start + \
"&output=mobile&site=local&saddr=" + end + \
"&btnG=Como+chegar"
GHTML = urllib.urlopen(rout_link)
parser = Rout()
parser.feed(GHTML.read())
return parser
 
def get_rout(start, end):
end = end.replace(" ", "+")
start = start.replace(" ", "+")
start = start.encode('utf-8')
end = end.encode('utf-8')
parser = parser_html(start, end)
routlist = parser.return_list()
parser.close()
return routlist
 
routlist = get_rout(START_LOCATION, END_LOCATION)
 
try:
for element in routlist:
print unicode(element,'latin-1')
except:
print "Destination does not exist"


Postconditions

If all run ok we will get this result:

Head south on Av. Santa Catarina toward Av. Mato Grosso - 30 m
Turn left at Av. Mato Grosso - 0.2 km
Turn left at Av. Amazonas - 0.2 km
Turn right at Av. Espírito Santo - 1.1 km
Continue on R. Prof. Joaquim F V Galvão - 0.8 km
Turn right at BR-230 - 0.3 km
Slight right to stay on BR-230 - 10.8 km
Continue on BR-101 - 6.9 km
Exit onto BR-230 - 108 km
Continue on Av. Pref. Severino Bezerra Cabral - 2.9 km
Slight left at Av. Canal Go through 1 roundabout - 1.1 km
Make a U-turn at R. Tomaz Soares de Souza - 55 m
84 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved