Hi Jeffrey,
Thanks for your reply.
I created a sample project but couldn't replicate the error, so I was
messing around with the code and I realised that my mapping form and map
object were working fine the first time I opened the form, but when I closed
the form and re-opened it I was getting the RPC error straight away, so I
thought it must be something not being disposed of properly? I checked all my
objects and couldn't see what it would be, and noticed that in the CalcPos
function (see below) the variable locNorthPole was not nothing when used when
the form was opened for the second time, whereas I was expecting it to be
nothing. This CalcPos function was a public function in a module, as I use it
in more than one form. I copied the CalcPos function to the form classes of
the forms that use it (i.e. so each form uses it's own local declaration of
the function), and now locNorthPole is nothing everytime I open a new
instance of the form and the error has gone.
I don't completely understand what the cause was, but I guess something was
staying in memory and not allowing the new instance of mappoint to work
properly?
Note: CalcPos is a procedure edited from code provided by mp2kmag.com
Thanks,
Kath
Public Sub CalcPos(ByRef objMap As MapPoint.Map, ByRef locX As
MapPoint.Location, ByRef dblLat As Double, ByRef dblLon As Double)
Try
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. cos variables are static,
they keep their last value
' when this sub is next called, so we don't need to recalc these
values
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) * Math.PI
'Compute Longitude from great circle distance
dblLon = 180 * Acos((Cos((d * 2 * Math.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
MapPointFuncRetry = 0 ' reset
Catch ex As Exception
WriteToLog(" ERROR in CalcPos - " + ex.Message)
' If MapPoint is too busy, we get 'RPC unavailable' error msg,
so check for this and retry if nec.
If ex.Message.IndexOf("RPC") > -1 Or
ex.Source.IndexOf("MapPoint") > -1 Then
If MapPointFuncRetry < 2 Then
' recall this procedure up to 2 times (so runs 3 times
in all)
MapPointFuncRetry += 1
CalcPos(objMap, locX, dblLat, dblLon)
Else ' return these flag values, to flag that it has failed
MapPointFuncRetry = 0 ' reset
WriteToLog(" in CalcPos, returning -1 for both")
dblLat = -1
dblLon = -1
End If
Else
MapPointFuncRetry = 0 ' reset
WriteToLog(" in CalcPos, returning -1 for both")
dblLat = -1
dblLon = -1
End If
End Try
End Sub
"Jeffrey Tan[MSFT]" said:
Hi Kath,
Ok, I understand now that you are using the MapPoint COM component of
MapPoint product.
There is not much special in the call stack.
Can you provide the full code snippet of function CalcPos method? It will
be helpful to understand your code logic.
Also, is it possible for you to provide the detailed steps and a sample
project for me to reproduce the problem? This will be more efficient for us
to troubleshoot it.
Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.