0

I have an array of 'names/locations' which each need to be geocoded to get latlng.

How can I convert this array of 'names/locations' into separate arrays for each of the names consisting of [name,latlng,markerimage].
Don't worry about the image path as it is seperate, but I am having a bit of trouble understanding how I can split the original array into an array for each item, which then needs to be geocoded to get the the second value of the array.

It is probably easier to try and visulize it rather understanding my explanation.
For Example:

My original array:
OriginalArray = ["Alkimos", "Ararat Lunatic Asylum", "Ballarat Jail", "Beechworth Lunatic Asylum", "Brisbane City Hall", "Dreamworld", "Lalor House", "Monte Cristo Homestead", "North Head Quarantine Station", "Port Arthur", "Princess Theatre Melbourne", "Whepstead House", "Victoria Park Railway Tunnel"]

This then needs to be displayed in the following format.

        var mapMarkers# = [Name[0],geocoded latlng of Name[0], image address],
                  [Name[1],geocoded latlng of Name[1], image address], etc

An example that doesn't deal with original array is:

        var mapMarkers5 = [
            ["<em>Marker 5(Yowie/Bigfoot)</em>", -28.4543, 152.872, "images/bigfoot-icon.jpg"],
            ["<em>Marker 6(Other)</em>", -28.1143, 151.872, "images/other-icon.png"],
            ["<em>Marker 7(Ghost)</em>", -29.4543, 154.872, "images/ghost-icon.jpg"],
            ["<em>Marker 8(UFO)</em>", -27.943, 151.242, "images/ufo-icon.png"],
        ];

What I want to do: For all the items in the original array

       var mapMarkers6 = [ 
           ["<em>Alkimos</em>", Alkimos(geocode).latlng, "images/bigfoot-icon.jpg"],
           ["<em>Ararat Lunatic Asylum</em>", Ararat Lunatic Asylum(geocode).latlng, "images/bigfoot-icon.jpg"],
           etc -->
           ["<em>Victoria Park Railway Tunnel</em>", Victoria Park Railway Tunnel(geocode).latlng, "images/bigfoot-icon.jpg"],
       ];


I honestly, don't really have much of an idea where to start with this as having to geocode the names throws a bit of a spanner in the works.

Would I do the Geocoding within a different function or just all as one?

user3663720
  • 305
  • 2
  • 12

1 Answers1

0

Just as example, you could do this with jquery like this:

var $arr = [2,1,4];
var $new = []
$.each($arr, function(index, item) {
    $new.push([item, 2*item]);
});

Result: [[2, 4], [1, 2], [4, 8]]

So while iterating over your initial array, you could just create the new array using the functions for geocoding.

For reference: detailed answer given here: How to loop through array in jQuery?, and http://api.jquery.com/each/

Community
  • 1
  • 1
matthias_h
  • 11,356
  • 9
  • 22
  • 40