Removing WebMapLocations

Hi,

Preamble

I need to convert to double a decimal value stored as a string (WebMapLocation.latitude and .longitude like (-8.12345, -9.12345) ). It becomes important to maintain the exact same format e.g. 5 numbers after the “.” to be able to remove the location from the active WebMapViewer. It seems to me that Google Maps does round coordinates to the 5th decimal.

When I convert them to double to use them as WebLocations coordinates, they end with 10 or so numbers after the “.”. That seems to make it impossible to use them to remove a location from the map. I’ve not been able to do it yet and I suspect that my value conversion is the source of the problem… Am I right?

Question

How to convert a string to double while defining the desired number of decimal values?

I’ve tried various solutions without success :
1- Lat = Val(Format(CDbl(Mid(Self.SitesListBox.Cell(i,1), 2, InStr(Self.SitesListBox.Cell(i,1), ",") -2)), "0.#####"))
2- Lat = CDbl(Mid(Self.SitesListBox.Cell(i,1), 2, InStr(Self.SitesListBox.Cell(i,1), ",") -2))*100000.0)/100000.0

Thanks for your help…

Roger

This will give you a maximum of 5 but not always 5
If you want a fixed number use 0.00000

VAL converts it back to a double which kind of negates the use of Format

What type is Lat ?

Lat is double and Long as well. I use these variables to temporarily store the WebLocations I want to add to my WebMapViewer.
When you choose a task, the sites related to that task are shown in a WebListBox called “SitesListBox”. Those sites are the ones I put on the map with the following code. I works fine.

    For i = 0 To Self.SitesListBox.RowCount-1
      Dim MyLocation As New WebMapLocation
      Lat = CDbl(Mid(Self.SitesListBox.Cell(i,1), 2, InStr(Self.SitesListBox.Cell(i,1), ",") -2))
      Long = CDbl(Mid(Self.SitesListBox.Cell(i,1), InStr(Self.SitesListBox.Cell(i,1), ",")+1, Len(Self.SitesListBox.Cell(i,1)) - InStr(Self.SitesListBox.Cell(i,1),",")-1)) // Data is stored as (-9.12345,-8.12345)
      MyLocation.Latitude = Lat
      MyLocation.Longitude = Long
      MyLocation.Title = Self.SitesListBox.Cell(i,0)
      MyLocation.Animated = True
      Self.ProjMapViewer.AddLocation(MyLocation)
      If i = Self.SitesListBox.RowCount-1 Then Self.ProjMapViewer.GoToLocation(MyLocation)
    Next i

I want the user to be able to remove the WebLocations they added so they can put a new set of locations without having to deal with the previous ones.

I thought I could use the following loop to remove them but they stay right in place…

[code]

For i = 0 To Self.SitesListBox.RowCount-1
Dim MyLocation As New WebMapLocation
Lat = CDbl(Mid(Self.SitesListBox.Cell(i,1), 2, InStr(Self.SitesListBox.Cell(i,1), “,”) -2))
Long = CDbl(Mid(Self.SitesListBox.Cell(i,1), InStr(Self.SitesListBox.Cell(i,1), “,”)+1, Len(Self.SitesListBox.Cell(i,1)) - InStr(Self.SitesListBox.Cell(i,1),",")-1))
MyLocation.Latitude = Lat
MyLocation.Longitude = Long
MyLocation.Title = Self.SitesListBox.Cell(i,0)
MyLocation.Animated = True
Self.ProjMapViewer.RemoveLocation(MyLocation)
Next i[/code]

It does not work. I know I should not use the New WebMapLocation since it already exists but if I don’t, MyLocation is not recognized as a WebLocation…

I can’t find my way out… :slight_smile:

Ah OK
Adding a location adds a reference to an object - not just a long & lat.
So when you want to remove one you nee to say “remove this object”.
When you create a new location like you are while it has the same coordinates its not the same object hence when you say “remove this object” the map viewer does not because its not the same object.
Conceptually you could have two pins in the exact same spot and you would not removing a long & lat to remove both.
You will probably need to keep your own list of locations you’ve added
Something like

  1. add a protected property to your window, mListOfLocationsAdded(-1) as WebMapLocation
    Then code like

[code] For i = 0 To Self.SitesListBox.RowCount-1
Dim MyLocation As New WebMapLocation
Lat = …
Long = ….
MyLocation.Latitude = Lat
MyLocation.Longitude = Long
MyLocation.Title = Self.SitesListBox.Cell(i,0)
MyLocation.Animated = True
Self.ProjMapViewer.AddLocation(MyLocation)

  // HERE you need to add the location to a list of places you added
  mListOfLocationsAdded.append MyLocation

  If i = Self.SitesListBox.RowCount-1 Then Self.ProjMapViewer.GoToLocation(MyLocation)
Next i

[/code]

Then to remove one you have to find the right object

For i = 0 To Self.SitesListBox.RowCount-1
      Dim MyLocation As WebMapLocation
      Lat = ...
      Long = ...

      // ok we need to find this one in our list of locations we added before … somehow …
      // but if you have 2 pins in the same spot how would you know which one ?
      for i as integer = 0 to unbound(  mListOfLocationsAdded )
           if mListOfLocationsAdded(i).Longitude = long and mListOfLocationsAdded(i).Latitude = lat then
                MyLocation = mListOfLocationsAdded(i)
                mListOfLocationsAdded.remove i
            end if
      next

      if myLocation <> nil then Self.ProjMapViewer.RemoveLocation(MyLocation)

    Next i

I try it and let you know how it went… Thanks!!!

It works like a charm!!!

Thank you very much!!!

I renamed the post so it represent better what your solution was for…

Do you know if it would be possible to implement layers and other properties using JavaScript code snippets provided by Google?

Thanks again!

Sorry I don’t