Json problem to load data into the Gmaps api

Asked

Viewed 134 times

1

I’m using Rails on a college project and added to Gmaps API to my project, in which I intend to display several points on the map picking the coordinates of a file JSON to create the cluster.

However the function I did does not work in any way, the map appears but without any point placed in it, I am also using the library jQuery. My file JSON is inside my briefcase Javascripts in the Rails, follows below my code:

<div id="map"></div>
    <script type= "text/javascript">
        //Opções de iniciação do mapa

        function initMap() {
            var cin = {lat: -8.055590, lng: -34.951344}
            var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 10,
            center: cin
        });


        //Função de carregar pontos do Json e jogar no mapa

        function carregarPontos() {
          $.getJSON('javascripts/pontos.json', function(pontos) {
             for (var i = 0; i < pontos.points.length; i++){
             var latLng = new google.maps.LatLng(pontos.points[i][0], pontos.points[i][1]);
             var marker = new google.maps.Marker({
             position: latLng,
             map: map
               });
            }

          });
        }

        //Infoboxes 

        var contentString = '<h1 id="pintest">Teste</h1>';
        var infowindow = new google.maps.InfoWindow({
            content: contentString
        });
            marker.addListener('click', function() {
                 infowindow.open(map, marker);
         });

        }
        //Iniciando função de carregar pontos

        carregarPontos();

My file Points.json is in this format:

inserir a descrição da imagem aqui I’m not sure if it’s in the right format, but I did the test with another file JSON that is in that format:

inserir a descrição da imagem aqui

And also does not rotate, my map appears but without any point in it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.