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
Results 1 to 7 of 7

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. #1
    jamesbond is offline 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. #2
    Wilfried is offline 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. #3
    jamesbond is offline Junior Member White Belt
    Join Date
    Nov 2005
    Posts
    3
    But I have no lat/long.

    What can I do?

  4. #4
    Wilfried is offline 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. #5
    jamesbond is offline 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. #6
    Wilfried is offline 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. #7
    calv1ns's Avatar
    calv1ns is offline Member Green Belt
    Join Date
    Mar 2005
    Posts
    91
    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,
    Calv1ns

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Office Interface, Lat & Long, Canada & Mexico Postal
    By The Lone Turtle in forum Wish List
    Replies: 0
    Last Post: 11-13-2005, 08:12 AM
  2. POSTAL CODE?????
    By Anonymous in forum Wish List
    Replies: 0
    Last Post: 02-12-2005, 06:01 AM
  3. Postal Code
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-14-2004, 04:08 PM
  4. How to get a postal code
    By huelsi in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 07-27-2003, 01:00 PM
  5. need postal code!
    By Anonymous in forum Wish List
    Replies: 0
    Last Post: 07-22-2003, 05:47 AM

Tags for this Thread

Posting Permissions

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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96