Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

 Subscribe to receive our newsletter. Subscribe Unsubscribe

## Lat/Long of my Postal Code

This is a discussion on Lat/Long of my Postal Code within the MapPoint Desktop Discussion forums, part of the Map Forums category; 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 ...

1. Junior Member White Belt
Join Date
Nov 2005
Posts
3

## Lat/Long of my Postal Code

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)

2. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
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?...xtract.lat.lon to find out.

3. Junior Member White Belt
Join Date
Nov 2005
Posts
3
But I have no lat/long.

What can I do?

4. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
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.

5. Junior Member White Belt
Join Date
Nov 2005
Posts
3
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
' header intact. Suggestions and comments welcome.

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)

' convert latitude to radian
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

6. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
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.

7. 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....mappoint.html

Good luck,
Ciao,

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•