Community of VE/MapPoint Users and Developers
This is a discussion on VB.net Calcpos within the MP2K Magazine Articles forums, part of the Map Forums category; Hello Experts I have attempted to use Gile Coles code to obtain the Latitude and longitude for a map position ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| VB.net Calcpos I have attempted to use Gile Coles code to obtain the Latitude and longitude for a map position resulting from a mouse event. I am using visual studio 2005, latitude and longitude are returned as 0 . Visual studio has altered the formula names in Accros Function from: Arccos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1) To: Arccos = Atan(-x / Sqrt(-x * x + 1)) + 2 * Atan(1) I believe these are only name changes in system.math,. The full codes used is reproduced below can you see the problem. Private Sub AxMappointControl1_BeforeDblClick(ByVal sender As System.Object, ByVal e As AxMapPoint._IMappointCtrlEvents_BeforeDblClickEven t) Handles AxMappointControl1.BeforeDblClick Try Dim objMap As MapPoint.Map objMap = Me.AxMappointControl1.ActiveMap Dim objDataSet As MapPoint.DataSet Dim txt1, txt2, txt0 As String Dim Ilat, Ilong As Double For Each objDataSet In objMap.DataSets 'clear pushpins If objDataSet.Name = "My Pushpins" Then objDataSet.Delete() End If Next Dim objResult As Object Dim objResults As MapPoint.FindResults 'Display the name of each object where user double-clicks on map objResults = objMap.ObjectsFromPoint(e.x, e.y) Dim i As Int16 = 0 For Each objResult In objResults If (i) = 0 Then txt0 = objResult.name If (i) = 1 Then txt1 = objResult.name If (i) = 2 Then txt2 = objResult.name i = i + 1 Next Dim objLoc As MapPoint.Location objLoc = objMap.XYToLocation(e.x, e.y) objMap.AddPushpin(objLoc, "Current location") objMap.AddPushpin(objLoc, "Current location").Highlight = True CalcPos(objMap, objLoc, Ilat, Ilong) txt0 = txt0 & ", " & txt1 & " ," & txt2 MsgBox("Current Location" & vbCrLf & txt0 & vbCrLf & Ilat & " Latitude" & vbCrLf & Ilong & " Longitude") Catch ex As Exception MsgBox(Err.Description) End Try End Sub I would value any help with this. Regards, Joe |
| ||||
| Re: VB.net Calcpos
It might help if we knew what your symptom was? (and if you think you have a CalcPos problem, seeing your CalcPos port might be useful...) Richard
__________________ Winwaed Software Technology LLC http://www.winwaed.com See http://www.mapping-tools.com for MapPoint Tools Pre-Order MapPoint 2009 today: http://www.mapping-tools.com/mappoint2009 |
| |||
| Re: VB.net Calcpos Hi Richard, Thanks for the response, I have reproduced the rest of the code below, the symptom is that I am not receiving a return from calcpos for the given location (“latitude and longitude are returned as 0”) Regards, Joe ' 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(ByVal x As Double) As Double If x = 1 Then Arccos = 0 Exit Function End If Arccos = Atan(-x / Sqrt(-x * x + 1)) + 2 * Atan(1) End Function Sub CalcPos(ByVal objMap As MapPoint.Map, ByVal locX As MapPoint.Location, ByVal dblLat As Double, ByVal 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 locNorthPole = objMap.GetLocation(90, 0) 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 Sub |
| ||||
| Re: VB.net Calcpos
Your longitude and latitude ordinates are defined as "byval". You must use ByRef. I assume that is what it is called in VB.Net - it is in VB6 (C# uses 'ref' and 'out'). byval is one way - data is passed into the function, but nothing is passed back. It is also good practice to use 'byref' for object parameters (eg. the location and map objects). This removes unnecessary copying/etc. (I'm not sure if I would trust a MapPoint.Map object that has been deep-copied) Richard
__________________ Winwaed Software Technology LLC http://www.winwaed.com See http://www.mapping-tools.com for MapPoint Tools Pre-Order MapPoint 2009 today: http://www.mapping-tools.com/mappoint2009 |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CalcPos in python | Loggy | MapPoint 2006/2009 Discussion | 1 | 08-31-2006 09:40 PM |
| Please help me with calcpos | chris701 | MapPoint 2006/2009 Discussion | 1 | 08-11-2006 11:55 AM |
| Some concerns about calcpos sub | lucci56 | MapPoint 2006/2009 Discussion | 5 | 07-18-2006 10:44 AM |
| Problems using CalcPos | Pete_ADL | MapPoint 2006/2009 Discussion | 4 | 06-21-2006 03:12 PM |
| Confused with calcpos :s | Matrices | MapPoint 2006/2009 Discussion | 4 | 09-25-2003 09:30 AM |
Cheap Flights from Manchester
Book cheap flights from Manchester Airport from a range of Tour Operators and airlines. Holiday Hypermarket will help you jet off. Visit online to find useful airport information too.
Flights to Italy
Find and book flights to Italy. Travel Counsellors can help with travel to Italy including flights and accommodation.
Cuba Holidays
After years of neglect by the western world, Cuba is coming back onto the holiday scene. Cuba Holidays are a unique and enjoyable experience. Book at dealchecker.co.uk.
Jamaica Holidays
Jamaica holidays give you the chance to enjoy the vibrant cultural heritage and wonderful laid back atmosphere of the Caribbean. Book here!
Egypt
In Egypt you find an ancient city buzzing with life. There is an abundance of historical sites to see, not just the pyramids. The Opera House is certainly worth a visit and you can enjoy some open-air theatre too.
All inclusive holidays
To plan all inclusive holidays, use Travel.co.uk to explore all the possibilities.
Cheap Holidays in Goa
Visit the unique blend of east and west in India! Get information on cheap holidays in Goa, only at On The Beach.