0

I've read and tested hundreds of samples and suggestions, but none of them seem to work for me.

Using winForms webControl I'm trying to pass in to the google maps api an array of addresses where will make a stop on the way.

Without the stops array everything works just fine. Here is the code samples:

JavaScript:

 function calcRoute(origin,destination, way ) 
 {
 var waypts = [];

 for (var i = 0; i < way.length; i++) {
             waypts.push({
              location:way[i],
              stopover:true});}
.....

VB.net

   Private Sub GetDirections_Click(sender As Object, e As EventArgs) 
        Dim origin As String = "1 Main St"
        Dim destination As String = "200 Main St"
        Dim wayP = New System.Web.Script.Serialization.JavaScriptSerializer().Serialize({"123Main St.", "189 Main St"})
        InvokeScript("calcRoute", origin, destination, wayP)
    End Sub

    Private Function InvokeScript(name As String, ParamArray args As Object()) As Object
        Return WebBrowser1.Document.InvokeScript(name, args)
    End Function

EDIT: the output I need to get in javascript is:

        [{
          location:"10201"
        },
        {
          location:"10202"
        }]
Ezi
  • 2,212
  • 8
  • 33
  • 60
  • someone here has anything to add? any suggestion? – – Ezi Mar 26 '14 at 02:48
  • What is your expected output? – Amit Joki Mar 26 '14 at 03:36
  • I added a sample array output in the question. – Ezi Mar 26 '14 at 14:18
  • You're inputing an array of strings and expecting to get an array of objects out. You need to create a simple class with a `location` property, and serialize an array of those objects. – Smeegs Mar 26 '14 at 14:24
  • after digging I see that the problem here is that javascript translate it to a string not a object, I guess I need to cast it or something on the javascript side. – Ezi Mar 26 '14 at 15:59
  • 1
    Got it... http://stackoverflow.com/questions/1086404/string-to-object-in-js, @Smeegs please post you're comment as an answer so I could accept it and close that. – Ezi Mar 26 '14 at 16:08
  • @Ezi, thanks :) it's been posted. – Smeegs Mar 26 '14 at 16:36

1 Answers1

1

You're inputing an array of strings and expecting to get an array of objects out. You need to create a simple class with a location property, and serialize an array of those objects.

Smeegs
  • 9,151
  • 5
  • 42
  • 78