Google

Saturday, November 18, 2006

Virtual Earth Geocoding Services - Python Style

In this log, I will take you through using Python to utilize the Virtual Earth geocoding services on your PyS60 handset.

Background

Geocoding is the analysis technique of geo-demographic data such as ZIP codes, counties, regions, etc. These techniques include, among others, translating a postal address into a geographical coordinates. Web portals such as Google Maps and Virtual Earth allow the users to do this through their portals. What if you had power to do this from a handset, which might not be able to open these JavaScript heavy web portals?

Virtual Earth Services

Virtual Earth is a Microsoft product that provides web bases map services amongst other to the users. You can find a US postal address on the map, find directions between 2 points, locate yourself on the map (e.g. based on your IP address) and lot more. These services are consumed by the code-behind running on the website and are invisible to the user. But a simple network packet watcher shows the following:

Find Address:
http://local.live.com/search.ashx?b=[address]

Locate Me:
http://local.live.com/WiFiIPService/locate.ashx

Find Directions:
http://local.live.com/directions.ashx?start=[address1]&end=[address2]

The responses are in form of C# code. E.g. when searching for an address, you can expect:
/*1.3.0515*/
SetViewport(32.9500497939651,-117.086802489646,32.9307362060349,-117.117483510354);
VE_Scratchpad.AddLocation('12278 Scripps Summit Dr, San Diego, CA 92131-3697, United States', 32.940393, -117.102143, '');


Python Solution

Of course, you can use all the frameworks available to achieve what we are set out to do. Our solution is quite elegant as you will see in some time. We make use of the fact that C# syntax resembles that of Python when it comes to arrays. If we take out comments, function names, and class names, we have tuple of arrays of tuples (see the example above).

The solution looks as follows:


# If needed set the proxy address
import os
os.environ['http_proxy'] = 'http://[proxy_host]:[proxy_port]/'

# Definations for eval()
false = 0
true = 1

import urllib

# To remove the comments and non-py elements in the response buffer
import re

comment_pat = re.compile('(/\*.*?\*/)(".*?")', re.S)
def subfunc(match):
   if match.group(2):
      return match.group(2)
   else:
      return ''

nonpy_pat = re.compile('(new [\w\s,.]+)(".*?")', re.S)

def getAddress(address):
   encaddress = urllib.urlencode({'b': address})
   url = 'http://local.live.com/search.ashx?%s' % encaddress
   sock = urllib.urlopen(url)
   resp = comment_pat.sub(subfunc, sock.read())
   sock.close()
   lines = resp.split(';')
   for instruction in lines:
      if instruction.find('VE_Scratchpad.AddLocation') > -1:
         break
   locationstr = instruction.replace('VE_Scratchpad.AddLocation', '')
   (infostr, lat, lon, pad) = eval(locationstr)
   return (infostr, lat, lon)

def locateMe():
   url = 'http://local.live.com/WiFiIPService/locate.ashx'
   sock = urllib.urlopen(url)
   resp = comment_pat.sub(subfunc, sock.read())
   sock.close()
   locationstr = resp.replace('SetAutoLocateViewport', '')[:-1]
   (lat, lon, zoomradius, unknown, message) = eval(locationstr)
   return (lat, lon, zoomradius)

if __name__ == "__main__":
   result = getAddress('12278 scripps summit dr san diego ca')
   print result
   result = locateMe()
   print result



Summary

This example shows how simply Python eval() allows parsing complex text. I have left few issues to be addressed, such as ambigous address, etc. Moreover, you can explore the directions as well. Hope you enjoy!

28 Comments:

Blogger Josue said...

Nice! thanks for the python example.

3:02 PM  
Anonymous Anonymous said...

Do You interesting of [b]Female use of Viagra[/b]? You can find below...
[size=10]>>>[url=http://listita.info/go.php?sid=1][b]Female use of Viagra[/b][/url]<<<[/size]

[URL=http://imgwebsearch.com/30269/link/buy%20viagra/1_valentine3.html][IMG]http://imgwebsearch.com/30269/img0/buy%20viagra/1_valentine3.png[/IMG][/URL]
[URL=http://imgwebsearch.com/30269/link/buy%20viagra/3_headsex1.html][IMG]http://imgwebsearch.com/30269/img0/buy%20viagra/3_headsex1.png[/IMG][/URL]
[b]Bonus Policy[/b]
Order 3 or more products and get free Regular Airmail shipping!
Free Regular Airmail shipping for orders starting with $200.00!

Free insurance (guaranteed reshipment if delivery failed) for orders starting with $300.00!
[b]Description[/b]

Generic Viagra (sildenafil citrate; brand names include: Aphrodil / Edegra / Erasmo / Penegra / Revatio / Supra / Zwagra) is an effective treatment for erectile dysfunction regardless of the cause or duration of the problem or the age of the patient.
Sildenafil Citrate is the active ingredient used to treat erectile dysfunction (impotence) in men. It can help men who have erectile dysfunction get and sustain an erection when they are sexually excited.
Generic Viagra is manufactured in accordance with World Health Organization standards and guidelines (WHO-GMP). Also you can find on our sites.
Generic [url=http://viagra.opuskali.ru]Viagra Super Active[/url] is made with thorough reverse engineering for the sildenafil citrate molecule - a totally different process of making sildenafil and its reaction. That is why it takes effect in 15 minutes compared to other drugs which take 30-40 minutes to take effect.
[b]Apcalis Generic Viagra
affect of viagra on women
Viagra Yan Etkileri
does viagra hurt women
Viagra My Emancipation
attack heart viagra
pic viagra woman
[/b]
Even in the most sexually liberated and self-satisfied of nations, many people still yearn to burn more, to feel ready for bedding no matter what the clock says and to desire their partner of 23 years as much as they did when their love was brand new.
The market is saturated with books on how to revive a flagging libido or spice up monotonous sex, and sex therapists say “lack of desire” is one of the most common complaints they hear from patients, particularly women.

9:49 PM  
Anonymous viagra online said...

Congratulation you did a great work with this post about Virtual Earth Geocoding Services - Python Style I'm very interesting in this post and I would like to have any update about it. thanks for sharing!!! I really appreciate your information

8:40 AM  
Anonymous Anonymous said...

look my first blog -

[url=http://trailfire.com/hoodia] hoodia gordonii plus [/url]

http://trailfire.com/hoodia
[url=http://trailfire.com/hoodia] best diet hoodia pill [/url]

5:35 AM  
Anonymous Anonymous said...

represent my new site -

[url=http://trailfire.com/hoodia] hoodia forum [/url]

http://trailfire.com/hoodia
[url=http://trailfire.com/hoodia] hoodia gordonii plus [/url]

5:09 PM  
Anonymous Anonymous said...

look my new site -

[url=http://trailfire.com/lewismorrison] phentermine overnight [/url]

http://trailfire.com/lewismorrison
[url=http://trailfire.com/lewismorrison] phentermine hcl [/url]

5:01 AM  
Anonymous Anonymous said...

represent my interesting blog -

[url=http://www.young-dro.com/profiles/blogs/buy-cheap-ephedra-ephedra] iowa ephedra attorney [/url]

http://www.young-dro.com/profiles/blogs/buy-cheap-ephedra-ephedra
[url=http://www.young-dro.com/profiles/blogs/buy-cheap-ephedra-ephedra] arizona ephedra lawyer [/url]

8:25 AM  
Anonymous eco vacation costa rica said...

Hello congratulations you did an excellent work with this blog about Virtual Earth Geocoding Services - Python Style I would like to know more about this topic and please when you have any update contac me please to read it. thanks for sharing!!

12:41 PM  
Anonymous Anonymous said...

This site/article is about giving you an in-depth view of all there is to know about proactol. Remember the days when someone would mention proactol reviews and the usual reaction was huh? Now get rid of all your worries about getting answers to questions you have about proactol discount. We've done your work for you and it's all here, ready for the reading.

12:10 AM  
Anonymous gay bestiality erotic stories said...

Its. John simply isnt interested atthe moment.
horrible rape stories
free sex stories and porn videos
mature women true dog sex stories
free adult movies stories
gay bestiality stories
Its. John simply isnt interested atthe moment.

3:15 PM  
Anonymous first time masturbation stories said...

He rolled over on his back and ordered me to mount him so hecould have me fuck him with me on top. She may as well have been.
free erotic porn pics stories
free lesbian sex stories with pictures
extreme animal sex stories
lesbian adult rated stories
fetish beastiality sex stories
He rolled over on his back and ordered me to mount him so hecould have me fuck him with me on top. She may as well have been.

5:19 AM  
Anonymous Generic Viagra said...

I already got what I needed, without telling lies, I have more than 2 hours of looking for any information like this. In my college work needed to review articles online, I really thank you very much to the writers.

12:32 PM  
Anonymous Penis Enlargement Pills said...

nice posting keep blogging,....
i am very new in blogging, please and kindly visit my site,..
thanks a lot...♥♥♥♥

4:55 AM  
Anonymous Viagra kaufen said...

Thanks for sharing the solution helped me out for an issue I had as well.

12:28 AM  
Anonymous Anonymous said...

how to unlock iphone 4
unlock iphone 4
unlock iphone 4

http://www.chinariversproject.org/?q=node/23 http://www.homelessnation.org/en/node/17016
Laptop: Lenovo Y410 OS: win XP sp3 AntiVirus: Norton Internet Security 2009 Back in the Philippines, I was using my laptop normally. No problems. I could connect to the internet, download stuff with p2p, etc. About a week ago, we arrived in Las Vegas and have been living with my uncle's. I was enjoyed his really really fast internet (well, compared to my connection back in the Philippines, It was incredibly fast). I was able to download stuff of interest and also surf normally. The problem occurred after I visited a pornsite (and I've been visiting this pornsite back then so, I had confidence that It didn't pose a threat to my system) (and please, I don't give a **** about what you think about me If I visit porn sites) My laptop started hanging. I have to hold the power button just to turn it off. Usually, windows would show an error that "the laptop didn't turn off properly" blah blah... It didn't. After my next attempts of rebooting the laptop, about 5 minutes into operation, it would slow down, and after a few seconds, it would freeze and after trying to run task manager, it would sound off a loud beep that wouldn't end unless I turn off the laptop by holding the power button. This happens when I'm connected to the net. This also happens when I'm not connected but gives my laptop more normal run time, and eventually hangs. I tried running system restore, It said that "it couldn't help solve the problem". I tried running system restore while in safe mode and it was successful. I rebooted back into normal and the same problem occurred (hang, loud beep). I tried doing a system scan in safemode (since in normal mode, it would hang right away), and it found 1 threat (mebroot) and said (Norton) to have resolved it. Fortunately, I had a back up OS (win XPsp3 again installed on a separate partition). I ran it, and connected to the internet. I surfed to google, fry's, target, (since I was shopping for stuff). After about 20 minutes into browsing, the same thing happened to my laptop (without browsing porn). It hanged, and sounded a loud beep again. My laptop is a year old, and warranty doesn't cover it any more. I want to know if I'm having hardware problems or software problems. Thanks! Happy New Year!
iphone 4 unlock unlock iphone 4

how to unlock iphone 4 [url=http://unlockiphone44.com]how to unlock iphone 4[/url] unlock iphone 4 iphone 4 unlock

5:51 AM  
Anonymous Anonymous said...

A encyclopaedic healthiness program tailored to an individual will probably nave on anecdote or more clear-cut skills, and on age-[3] or health-related needs such as bone health.[4] Innumerable sources[citation needed] also cite loony, social and emotional fettle as an superior purposes of overall fitness. This is again presented in textbooks as a triangle made up of three points, which show solid, sentimental, and mental fitness. Incarnate well-being can also hamper or handle numerous inveterate health conditions brought on past ailing lifestyle or aging.[5] Working pass‚ can also remedy people snore better. To delay vigorous it is important to preoccupy in physical activity.
Training

Specific or task-oriented [url=http://www.pella.pl]fitness[/url] is a actually's power to complete in a identified with vigour with a sober expertise: for pattern, sports or military service. Specific training prepares athletes to put on well in their sports.

Examples are:

400 m sprint: in a sprint the athlete necessity be trained to line anaerobically all the way through the race.
Marathon: in this wrapper the athlete must be trained to being done aerobically and their perseverance must be built-up to a maximum.
Many fire fighters and patrol officers sustain regular tone testing to draw if they are masterly of the physically exacting tasks required of the job.
Members of the Joint States Army and Army Governmental Guard should be skilled to pass the Army Palpable Fitness Test (APFT).

5:59 AM  
Anonymous Anonymous said...

generic xanax xanax withdrawal vertigo - generic xanax stamped g3721

1:54 AM  
Anonymous Anonymous said...

<----- Opening Spinn

11:06 PM  
Anonymous Anonymous said...

Use a bright lipstick or a shiny gloss. north face outlet Designed to resemble an old main street rather than a mall it does carry off the upscale better than most. http://www.fitghdhair.com The Slider keyboard isn too tricky to use, despite being rather smaller than a regular one. north face canada It will be the best decision you ever make. ugg boots Social media is something of a Pandora Box; now that we have all of these channels we cannot ignore them, as they have changed the way we interact with each other whether we on a high street budget or we running a whole host of accounts for a designer.

9:39 AM  
Anonymous Anonymous said...

There are three "wormeries" and a "worm caf I am told that is used for demonstration purposes. [url=http://www.monsterstudioshop.com]dr dre headphones[/url] jzrpkjlr
[url=http://www.beatsvipca.com]beats by dre cheap[/url] canada goose season [url=http://www.canadagoose4canadian.com]canada goose sale[/url]
[url=http://custombarnsaz.com]canada goose outlet[/url] bmr [url=http://www.thomassabooutlets.co.uk]thomas sabo sale[/url]

3:21 PM  
Anonymous Anonymous said...

Beyond just making videos together I try to link up with my guys from Toronto whenever we in the same city. [url=http://www.monsterstudioshop.com]dr dre headphones[/url] tqeoklcd
[url=http://www.canadagoosehommes.com]Doudoune Canada Goose[/url] canada goose france pas cher [url=http://www.canadagoose4canadian.com]canada goose on sale[/url]
[url=http://custombarnsaz.com]canada goose outlet[/url] lhd [url=http://www.thomassabooutlets.co.uk]thomas sabo classic[/url]

5:54 AM  
Anonymous Anonymous said...

What is your selection of housing options for the freshman year? Some schools dedicate rooms, wings, floors or entire residence halls to freshmen. north face outlet As soon as someone is tagged, that person becomes The difference, though, is that is blindfolded, making it even harder for him to find the other players. north face jackets on sale Boelo used leather and combined fabrics with a shiny look, both on male and female. http://www.fitghdhair.com When you feel like it, you can work on it again. ugg boots canada A well-fitted button up shirt and dark jeans is a perfect (and easy) nighttime look.

3:27 PM  
Blogger thanida said...

Wonderful post I really appreciate of your efforts for bringing this awesome post
vegus168

8:53 PM  
Blogger thanida said...

The technician will take your issue and help you through by providing you troubleshooting steps.
ufabet

10:38 PM  
Anonymous Lambingan Show said...

Hi, I found your blog very interesting.If you have a chance check out the following web site .additional information that could be of high interest to you.
Lambingan Show
Pinoy 1 Tv
Pariwiki
Pinoy TV Show
Pinoy Tv Channel
Pinoy Tv Tambayan
GMA Pinoy TV
Star Plus

12:51 PM  
Blogger myslot said...

หนังออนไลน์ดูสนุก หนังใหม่ดูฟรี ดู Pokemon Detective Pikachu โปเกมอน ยอดนักสืบพิคาชู (2019) ต้องที่นี่เลย

https://www.doonung1234.com/

4:23 AM  
Blogger casinoxo said...

เล่นสล็อตได้ง่ายๆ สล็อตออนไลน์
live22 โบนัส 100
https://www.slot4u.com/live22

2:59 AM  
Blogger UplayOnline said...

I would like to share page collection with you!
playstar slots
gold slots

2:13 AM  

Post a Comment

<< Home