Community of MapPoint and Virtual Earth Users and Developers
This is a discussion on Obtain LatLong with Address within the MapPoint Web Service and Virtual Earth 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 ...
| |||||||
| Today's Posts | Twitter Feed | Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Obtain LatLong with Address 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 |
| ||||
|
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 See the Geoweb Guru for online mapping |
| |||
| 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 |
| |||
| 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 |
| |||
| Re: MapPoint 2006 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? |
![]() |
| Tags |
| address, latlong, obtain |
| ||||
| Posted By | For | Type | Date | |
| Aide pour mappoint europe 2006] - PC SOFT - Forum consacré à WinDev | This thread | Refback | 04-21-2009 08:03 AM | |
| Aide pour mappoint europe 2006] - PC SOFT - Forum consacré à WinDev | This thread | Refback | 09-25-2008 05:23 AM | |
| PC SOFT - Forums dveloppeurs | This thread | Refback | 04-28-2008 04:05 AM | |
| PC SOFT - Forums dveloppeurs | This thread | Refback | 04-24-2008 04:48 AM | |
| PC SOFT - Forums dveloppeurs | This thread | Refback | 04-22-2008 11:16 AM | |
| PC SOFT - Forums dveloppeurs | This thread | Refback | 04-22-2008 09:54 AM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| LatLong to Address ?? | xaxas | MapPoint 2006/2009 Discussion | 5 | 10-19-2008 09:16 PM |
| Getting informations about geographic coordinates (LatLong) | badzio | MapPoint Web Service and Virtual Earth | 4 | 08-02-2005 08:34 AM |
| Obtain X, Y from Lat, Long | mikica1972 | MapPoint 2006/2009 Discussion | 1 | 10-27-2003 07:47 AM |
| How to obtain ZIP code from lat-long? | BC | MapPoint 2006/2009 Discussion | 1 | 04-29-2003 05:49 AM |
| Is there a way I can obtain a copy of the EULA for.... | Anonymous | MapPoint 2006/2009 Discussion | 1 | 07-30-2001 07:57 AM |
Zante Holidays
Enjoy lovely sandy beaches when you take your Zante holidays booked through UlookUbook!