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 6 of 6

Obtain LatLong with Address

This is a discussion on Obtain LatLong with Address within the Bing Maps and MapPoint Web Service forums, part of the Map Forums category; Hi! I have a problem: I've a form in wich I put some address data: city, postcode, direction, etc. The ...

  1. #1
    ivan is offline Junior Member White Belt
    Join Date
    Feb 2006
    Posts
    11

    Obtain LatLong with Address

    Hi!
    I have a problem:
    I've a form in wich I put some address data: city, postcode, direction, etc.
    The question is: can i obtain the latlong of this place with an address object? And how do it? Are there any method or function for do it?
    Many thanks!
    Ivan

  2. #2
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    You need Gilles Kohl's "CalcPos()" routine. Do a search on this website to find it (sorry don't have the URL handy).
    This is in VB6 and takes a location object, and returns the longitude,latitude coordinate using some cunning geometry.

    It is easily ported to other languages (I've ported it to C++ and FoxPro in the past), although you should keep the double precision maths.


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  3. #3
    Mark - MSFT is offline Junior Member Yellow Belt
    Join Date
    Dec 2005
    Posts
    22

    MapPoint 2006

    Also, the new version (due out this month) of MapPoint does have a Lat/Lon method which allows you do dump your lat lons programmatically.


    Mark - MSFT

  4. #4
    AUR
    AUR is offline Junior Member White Belt
    Join Date
    Dec 2006
    Posts
    11

    Re: Obtain LatLong with Address

    Hello Mark

    I've a problem, i need to export all streets addresses+lat/lon into an external file ( this is the builtin mappoint dataset), so that later i can import in access database and show it on access forms and communicate with Map point.

    Please can you help me.

    regards
    AUR

  5. #5
    shaistasohail is offline Junior Member Yellow Belt
    Join Date
    Sep 2002
    Posts
    20

    Re: Obtain LatLong with Address

    Ivan

    Here is some reference code to point you in the right direction. You will need to tweak it to get it to work. This should work for both MP2004 and 2006. For 2006 you can of course use the Lat/Lon method as Mark pointed out.


    Public Function FindContactEX(ByVal sAddress As String, _
    Optional ByVal ShowFindDialog As Boolean = True, _
    Optional ByVal AddPushPin As Boolean = False) As Object

    Dim objFindResults As MapPointCtl.FindResults
    Dim objLoc As Object
    Dim objPushPin As MapPointCtl.Pushpin
    Dim lngI As Long
    Dim strAddress As String
    Dim arrAddress As Variant
    Dim CountryObject As Object


    Set FindContactEX = Nothing

    MultipleMatches = 0
    Set m_FindResults = Nothing
    Set m_FindResults = New Collection

    strAddress = sAddress

    If Trim(strAddress) = "" Then
    Exit Function
    End If

    'Output first result of find search
    Set objFindResults = ctlMap.ActiveMap.FindResults(strAddress)

    If objFindResults.Count = 0 Or objFindResults.ResultsQuality > 2 Then
    If InStr(1, strAddress, ",") Then
    arrAddress = Split(strAddress, ",")
    If IsArrayDimensioned(arrAddress) Then
    Set objFindResults = ctlMap.ActiveMap.FindResults(arrAddress(UBound(arr Address)))
    If objFindResults.Count > 0 Then
    Set CountryObject = objFindResults.Item(1)
    Set objPushPin = ctlMap.ActiveMap.AddPushPin(CountryObject)
    objPushPin.Symbol = cPP_CONTACTRED
    CountryObject.GoTo
    End If
    End If
    End If
    Exit Function
    ElseIf objFindResults.Count >= 1 And objFindResults.Count <= 3 Then
    Set FindContactEX = objFindResults.Item(1)
    If AddPushPin Then
    Set objPushPin = ctlMap.ActiveMap.AddPushPin(FindContactEX, strAddress)
    objPushPin.Symbol = cPP_CONTACTRED
    FindContactEX.GoTo
    End If
    Else
    MultipleMatches = objFindResults.Count
    For lngI = 1 To objFindResults.Count
    Set objLoc = objFindResults.Item(lngI)
    If TypeOf objLoc Is MapPointCtl.Location Then
    m_FindResults.Add objLoc
    End If
    Next lngI

    If ShowFindDialog Then
    Set FindContactEX = ctlMap.ActiveMap.ShowFindDialog(strAddress, geoFindDefault)
    If Not FindContactEX Is Nothing Then
    If TypeOf FindContactEX Is MapPointCtl.Location Then
    Else
    Set FindContactEX = m_NewSelection ' m_NewSelection will be set in ctlMap_SelectionChange event
    End If
    End If
    End If
    End If

    End Function

    Public Sub GetGeoCodes(ByVal sAddress As String, _
    ByRef dblLat As Double, ByRef dblLon As Double, _
    Optional ByVal ShowFindDialog As Boolean = True, _
    Optional ByVal AddPushPin As Boolean = False)

    Static locNorthPole As MapPointCtl.Location
    Static locSantaCruz As MapPointCtl.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
    Dim objMap As MapPointCtl.Map
    Dim LocX As MapPointCtl.Location
    Dim l As Double
    Dim d As Double

    dblLat = 0#
    dblLon = 0#

    If ctlMap.ActiveMap Is Nothing Then
    Err.Raise vbError + 1000, "GetGeoCodes", "Map control does not have any active map."
    Exit Sub
    Else
    Set objMap = ctlMap.ActiveMap
    End If

    Set LocX = FindContactEX(sAddress, ShowFindDialog, AddPushPin)
    If LocX Is Nothing Then
    If (UseZipcodeMatching = True) And (ZipCode <> "") Then
    m_GeocodeLevel = GCNone
    Set LocX = FindContactEX(ZipCode, ShowFindDialog, AddPushPin)
    If LocX Is Nothing Then
    Exit Sub
    Else
    If UIMode = False Then
    m_GeocodeLevel = GCPostalCode
    Else
    m_FindResults.Add LocX
    Exit Sub
    End If
    End If
    Else
    Exit Sub
    End If
    Else
    m_GeocodeLevel = GCStreet
    End If

    ' 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

    ' 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

    RaiseEvent GotLatLong(dblLat, dblLon)

    If AddPushPin Then
    Set LocX = objMap.GetLocation(dblLat, dblLon)
    If Not (LocX Is Nothing) Then
    objMap.AddPushPin LocX, sAddress
    LocX.GoTo
    End If
    End If

    End Sub

  6. #6
    brandie is offline Junior Member White Belt
    Join Date
    May 2007
    Posts
    1

    Re: MapPoint 2006

    Quote Originally Posted by Mark - MSFT View Post
    Also, the new version (due out this month) of MapPoint does have a Lat/Lon method which allows you do dump your lat lons programmatically.


    Mark - MSFT
    I am aware of the CalcPos function - although I don't know where to actually paste the code. But I have a trial version of MapPoint 2006 and am not seeing the Lat/Long method mentioned above. When I export to Excel, lat/long is not included and there are no options to customize which fields go. Can someone point me in the right direction?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. LatLong to Address ??
    By xaxas in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 10-19-2008, 10:16 PM
  2. Getting informations about geographic coordinates (LatLong)
    By badzio in forum Bing Maps and MapPoint Web Service
    Replies: 4
    Last Post: 08-02-2005, 09:34 AM
  3. Obtain X, Y from Lat, Long
    By mikica1972 in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-27-2003, 08:47 AM
  4. How to obtain ZIP code from lat-long?
    By BC in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-29-2003, 06:49 AM
  5. Is there a way I can obtain a copy of the EULA for....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 07-30-2001, 08:57 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