MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




VB.net Calcpos

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


Go Back   MapPoint Forums > Map Forums > MP2K Magazine Articles

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-17-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Posts: 28
VB.net Calcpos

Hello Experts

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 10-17-2007
Winwaed's Avatar
Mapping-Tools.com
Red Belt
 
Join Date: Feb 2004
Posts: 759
Blog Entries: 1
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 10-17-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Posts: 28
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 10-17-2007
Winwaed's Avatar
Mapping-Tools.com
Red Belt
 
Join Date: Feb 2004
Posts: 759
Blog Entries: 1
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 10-17-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Posts: 28
Re: VB.net Calcpos

Hi Richard

I am fairly new to vb.net, as you will see from my code I still have a lot to learn.

Your suggested alterations sorted the problem out.

Thanks,
Joe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

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


All times are GMT -5. The time now is 01:47 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5
MP2K Magazine
Visitor Map

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.


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