Lotusscript geo-loc part II


* Remember my last post… opening the brower for the user with the map of the place diplayed in the notes document… I’m doing it better.
* You need to know that the in Switzerland there is a special way to record localisation. So you need some code to convert it in GPS to use them in Google.
* Here some links for you background :

‘ Some backgroup doc                 :        http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey.html
‘ Online source                        :         http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/products/software/products/skripts.html
‘ Java project to convert         :         http://www.i3s.unice.fr/~johan/gps/
‘ Online convertor                         :         http://topo.epfl.ch/misc/transcoco/transcoco_compute.php
* Here the GoogleMapStreetUrl version 2.0

Class GoogleMapStreetUrl

 Private sUrl            As String
 Private sStreet         As String
 Private sCity                 As String

 Private sZoom                As String

 Private apiUrl                List As String

 Private x                        As Double
 Private y                        As Double

 Private lat                As Double
 Private lng                As Double

 Private sGeoCode        As String

 Sub new()
 sZoom = 13

 apiUrl("STREET") = "http://maps.google.com/maps?f=q&source=s_q&hl=fr&geocode=&q=%LOC%,%STREET%"
 apiUrl("GEOCODE") = "http://maps.google.com/maps?f=q&source=s_q&hl=fr&geocode=&q=&sll=%1&z=%2&saddr=%3"

 'sUrl = "http://maps.google.com/maps?f=q&source=s_q&hl=fr&geocode=&q=%LOC%,%STREET%"
 End Sub

 Public Function setZoom(sZ As Integer) As Integer
 sZoom = Cstr(sZ)
 End Function

 Public Function setStreet(psStreet As String) As Integer
 sUrl = apiUrl("STREET")
 sStreet = Replace(psStreet, " ", "+")
 End Function

 Public Function setCity(psCity As String) As Integer
 sUrl = apiUrl("STREET")
 sCity = Replace(psCity, " ", "+")
 End Function

 Public Function getUrl() As String
 Dim sNewUrl As String
 sNewUrl = Replace(sUrl, "%LOC%",sCity)
 sNewUrl = Replace(sNewUrl, "%STREET%",sStreet)
 sNewUrl = Replace(sNewUrl, "%1", sGeoCode)
 sNewUrl = Replace(sNewUrl, "%3", sGeoCode)
 sNewUrl = Replace(sNewUrl, "%2", sZoom)
 getUrl = sNewUrl
 End Function

 Public Function setLatLong(lng As Double, lat As Double) As Integer
 sUrl =apiUrl("GEOCODE")
 sGeoCode = Cstr(lat) + "," + Cstr(lng)
 End Function

 Public Function setCH1903_YX(y As Double, x As Double) As Integer
 sUrl =apiUrl("GEOCODE")
 Dim g As New CH1903toWGS84
 sGeoCode = g.getLatLong(y, x)
 End Function

 Public Function setLat(lat As Double) As Integer
 sUrl =apiUrl("GEOCODE")

 End Function

 Public Function open() As String
 Dim url As String
 url = Me.getUrl()
 Call ShellExecute ( GetActiveWindow(), "open", url, "", "", WIN_NORMAL)
 End Function

End Class

Public Class CH1903toWGS84

 '
 ' Class to convert CH1903 to WGS84
 ' Some backgroup doc                 :        http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey.html
 ' Online source                        :         http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/products/software/products/skripts.html
 ' Java project to convert         :         http://www.i3s.unice.fr/~johan/gps/
 ' Online convertor                         :         http://topo.epfl.ch/misc/transcoco/transcoco_compute.php

 ' one sample
 '        CH1903        Y        537546
 '        CH1903        X        151681
 '
 ' --> gives
 '        WGS84        longitude        6.625644
 '         WGS84        latitude        46.514783

 Public Function getLatLong(y As Double, x As Double) As String
 Dim sTxt As String
 sTxt = Cstr(Me.CHtoWGSlat(y,x))
 sTxt = sTxt + "," + Cstr(Me.CHtoWGSlng(y,x))
 getLatLong = sTxt
 End Function

 Public Function CHtoWGSlat(y As Double, x As Double) As Double

 Dim  y_aux         As Double
 Dim  x_aux         As Double
 Dim         lat                 As Double

 y_aux = (y - 600000)/1000000
 x_aux = (x - 200000)/1000000

 lat = 16.9023892 +  3.238272 * x_aux -  0.270978 * (y_aux ^ 2) -  0.002528 * (x_aux ^ 2)        -  0.0447   * (y_aux ^ 2) * x_aux        -  0.0140   * (x_aux ^ 3)

 lat = lat * 100/36

 CHtoWGSlat = lat
 End Function

 Public Function CHtoWGSlng(y As Double, x As Double)  As Double
 Dim  y_aux         As Double
 Dim  x_aux         As Double
 Dim         lng                 As Double

 y_aux = (y - 600000)/1000000
 x_aux = (x - 200000)/1000000

 lng = 2.6779094 + 4.728982 * y_aux         + 0.791484 * y_aux * x_aux        + 0.1306   * y_aux * (x_aux ^ 2)
 lng = lng * 100/36
 CHtoWGSlng = lng
 End Function

End Class

Advertisements

About pierrekoerber
Hey, pour faire connaissance, laisse-moi un message... drop me a line.

3 Responses to Lotusscript geo-loc part II

  1. arf.. sorry for “Perre” instead of “Pierre”…

  2. Pierre Koerber says:

    Great, I will have a try… perhaps, see you !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: