-1

I have a JSON Array with attributes such as a Name, and lat and lon. I will place them on the map as markers. I would then like to use Google's Auto-complete places search to search for the "name" field in my array and display any markers that match the search. Is this possible?

 //global variables
var gmarkers1 = [];
var markers1 = [];
var infowindow = new google.maps.InfoWindow({
    content: ''
});

//add the shipwreck data
markers1 = [
  ["Name","Latitude","Longitude","Year","Type","Type_of_Loss"  ],
  ["Bermuda","46.46483333","-86.64683333","1870","Schooner","Storm"  ],
  ["George","46.516","-86.52083333","1893","Schooner","Storm"  ],
  ["Herman H. Hettler","46.48383333","-86.59966667","1926","Propeller","Storm"  ],
  ["Kiowa","46.64516667","-86.22016667","1929","Propeller","Storm"  ],
  ["Manhattan","46.467","-86.60933333","1903","Propeller","Storm"  ],

];


//initiate the map
function initMap() {
    // Our markers


    var center = new google.maps.LatLng(45.2858536, -83.8419731);
    var mapOptions = {
        zoom: 6,
        center: center,
        mapTypeId: google.maps.MapTypeId.TERRAIN
    };



    map = new google.maps.Map(document.getElementById('map'), mapOptions);
    for (i = 0; i < markers1.length; i++) {
        addMarker(markers1[i]);
    }
  // map.data.loadGeoJson('data/lakebath.geojson');
//    map.data.setStyle({
//  fillColor: 'green',
//  strokeWeight: 1,
//  strokeOpacity: 0.5        
//});
}


//add markers to the map
function addMarker(marker) {    
    var category_type = marker[4];
    var category_loss = marker[5];
    var category_year = marker[0];
    var title = marker[0];
    var pos = new google.maps.LatLng(marker[1], marker[2]);
    var content = marker[0];

    marker1 = new google.maps.Marker({
        title: title,
        position: pos,
        //setup the categories for the different mark types
        category_type: category_type,
        category_loss: category_loss,
        category_year: category_year,
        map: map
    });
kaskader
  • 1,931
  • 16
  • 24

1 Answers1

1

I don't believe this is possible - the Google Places API lets you search though Google's places, but not a locally-maintained array of one.

Instead of trying to use the Places API, I would just locally search through your markers1 array and see if the search term is a substring of the marker name.

Community
  • 1
  • 1
bamnet
  • 2,525
  • 17
  • 21
  • Right, that is what I was thinking as well but I am a novice to programming. Do you have any idea how I would go about coding that? Thank you. – timmyblaze Apr 14 '17 at 16:28
  • look for answers similar to this one: http://stackoverflow.com/questions/5424488/how-to-search-for-a-string-inside-an-array-of-strings – kaskader May 08 '17 at 12:52