PDA

View Full Version : Lat/Long of my Postal Code

jamesbond
11-23-2005, 02:42 PM
Hello guys,

it is possible to get Lat/Long of an Postal Code?

I found this:

http://www.mp2kmag.com/articles.asp?ArticleID=9

But why must show the Find Form from Mappoint?
Is it possible to make it with this code?

Set oPushA = oMap.FindAddressResults(Street, City, , , PLZ)

Wilfried
11-25-2005, 11:25 AM
Hi,

Yes, FindAddressResults give you a collection of Location objects. To get the lat / long you have to write some code yourself. Check also this article http://www.mp2kmag.com/articles.asp?ArticleID=13&key=extract.lat.lon to find out.

jamesbond
11-26-2005, 08:48 AM
But I have no lat/long.

What can I do?

Wilfried
11-26-2005, 11:47 AM
Hi,

No what you get in the results is a collection of Location objects. They do not contain the coordinates, but the article shows you an easy method of getting the coordinates from out of a Location object.

jamesbond
11-26-2005, 02:52 PM
But when I make an Function I must have an Parameter dblLat and dblLon.

Is this correct or what make i wrong?

' Compute latitude and longitude given a location object
' Author: Gilles Kohl
' (gilles@compuserve.com)
'
' This code is copyrighted freeware - use freely, but please leave this

Function Arccos(x As Double) As Double
If x = 1 Then
Arccos = 0
Exit Function
End If
Arccos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1)
End Function

Public Function CalcPos(objMap As MapPoint.map, locX As MapPoint.Location, dblLat As Double, dblLon As Double)
Static locNorthPole As MapPoint.Location
Static locSantaCruz As MapPoint.Location ' Center of western hemisphere
Static dblHalfEarth As Double ' Half circumference of the earth (as a sphere)
Static dblQuarterEarth As Double ' Quarter circumference of the earth (as a sphere)
Static Pi As Double

' Check if initialization already done
If locNorthPole Is Nothing Then
Set locNorthPole = objMap.GetLocation(90, 0)
Set locSantaCruz = objMap.GetLocation(0, -90)

' Compute distance between north and south poles == half earth circumference
dblHalfEarth = objMap.Distance(locNorthPole, objMap.GetLocation(-90, 0))

' Quarter of that is the max distance a point may be away from locSantaCruz and still be in western hemisphere
dblQuarterEarth = dblHalfEarth / 2
Pi = 3.14159265358979
End If

' Compute latitude from distance to north pole
dblLat = 90 - 180 * objMap.Distance(locNorthPole, locX) / dblHalfEarth

Dim l As Double
Dim d As Double

' Compute great circle distance to locX from point on Greenwich meridian and computed Latitude
d = objMap.Distance(objMap.GetLocation(dblLat, 0), locX)

l = (dblLat / 180) * Pi

' Compute Longitude from great circle distance
dblLon = 180 * Arccos((Cos((d * 2 * Pi) / (2 * dblHalfEarth)) - Sin(l) * Sin(l)) / (Cos(l) * Cos(l))) / Pi

' Correct longitude sign if located in western hemisphere
If objMap.Distance(locSantaCruz, locX) < dblQuarterEarth Then dblLon = -dblLon
End Function

Wilfried
11-27-2005, 02:09 PM
Hi,

Public Function CalcPos(objMap As MapPoint.map, locX As MapPoint.Location, dblLat As Double, dblLon As Double)

dblLat and dblLon are result pareameters, so as far as I can see quick from this example VB takes parameters by reference. so you have to define them and put on the stack before calling CalcPos.

calv1ns
11-29-2005, 05:47 PM
Wil is right...

The way Gilles wrote the routine is for the values of dblLat and dblLong to be passed back out of the subroutine. In VB6 the routine works great. In .net in addition to all the syntax changes you have to pass the two lat long varaibles "ByRef" so the routine has access to change them. This is all explained by Gilles here:

http://www.mp2kmag.com/a66--location.sensor.net.mappoint.html

Good luck,
Ciao,