-2

var gmarkers1 = [];
var markers1 = [];
var infowindow = new google.maps.InfoWindow({
    content: ''
});
markers1 = [
    ['0', 'Title', 52.4357808, 4.991315699999973, 'car'],
    ['1', 'Title', 52.4357808, 4.981315699999973, 'third'],
    ['2', 'Title', 52.4555687, 5.039231599999994, 'car'],
    ['3', 'Title', 52.4555687, 5.029231599999994, 'second']
];

I found this script, how can I import data from .txt files into markers1?

And second, how can I show my select on text with document.getElementById?

I show only title, like this, if I choose "car" to show only the title:

<div id="map-canvas"></div>
<select id="type" onchange="filterMarkers(this.value);">
    <option value="">Please select category</option>
    <option value="second">second</option>
    <option value="car">car</option>
    <option value="third">third</option>
</select>
full script here Google Map Pins - Filter by category
rishat
  • 8,206
  • 4
  • 44
  • 69
Rackal
  • 1
  • 2
  • 2
    Hi @Rackal, as a rule of thumb, you should provide [**_"Research Effort"_**](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) when [asking in StackOverflow](https://stackoverflow.com/help/how-to-ask). Also, I know writing in a second language is hard, I am not a native english speaker either, however I'm sure that if you take your time you could came out with a better question. – Luis Miguel Mejía Suárez Nov 10 '18 at 21:42
  • Thanks for the answer, I did my research on stacks but I did not find anything relevant. Unfortunately it does not let me put all the code for this and put the link. My question is simple. I want Markers1 = [] to read the data from txt files. Also, when I choose a category, I want to display the map results on a
    . I hope you understand me. Thanks.
    – Rackal Nov 10 '18 at 23:26
  • I'm not a front-end developer so I can't help you with the second question, but probably you could just **repaint** the contents of the `div ` when you choose a category _(attaching an action to the event of the radio button menu)_. For the first one, maybe [this](https://stackoverflow.com/a/17901752/4111404) can help? - as long as the file is in a server you could load it, or even better make a simple api that returns the data as a **JSON**, now if the file is local you would need the user to load it first. – Luis Miguel Mejía Suárez Nov 11 '18 at 16:56

1 Answers1

0

I have tried the following code

filterMarkers = function (category) {
    for (i = 0; i < markers1.length; i++) {
        marker = gmarkers1[i];
        // If is same category or category not picked
        if (marker.category == category || category.length === 0) {
            marker.setVisible(true);
        }
        // Categories don't match 
        else {
            marker.setVisible(false);
        }
        document.getElementById("demo").innerHTML = "You selected: " + marker[];
    }
<p id="demo"></p>

but it throws me [object]

To read from txt I can not convey it in some way. The file will be in a file server

Thank you for your time!

Rackal
  • 1
  • 2