View locations by searching for the address in the JSON file / Google Maps Api

Asked

Viewed 193 times

0

Hello, I’m in need of doing a search in the json file, where the attributes that will return me the location would address(Street, Number, Neighborhood, City) and with this information in hand javascript would need to convert to latitude and longitude to display on the map.

the code snippet where I try to make it work:

function carregaEnderecos() {
    $.getJSON('Scripts/pontos.json', function (pontos) {
        $.each(pontos, function (index, ponto) {
            var addressInput = document.getElementById(ponto).value;

            var geocoder = new google.maps.Geocoder();


            geocoder.geocode({ address: addressInput }, function (results, status) {

                if (status == google.maps.GeocoderStatus.OK) {

                    var myResult = results[0].geocoder.location;

                    createMarker(myResult);

                    title: 'Ponto';
                    icon: 'Images/location.png';
                    map.setCenter(myResult);
                    center: map;
                    map.setZoom(17);
                }

                infoBox[ponto.Id] = new InfoBox(myOptions);
                infoBox[ponto.Id].marker = marker;

                infoBox[ponto.Id].listener = google.maps.event.addListener(marker, 'click', function (e) {
                    abrirInfoBox(ponto.Id, marker);
                });

                latlngbounds.extend(marker.position);
            });
        });
    });
}

Thanks in advance!

  • What console.log(results[0].geocoder) returns?

  • Marconi, Returns null and void

  • You have enabled the APIS in the console to develop correctly?

  • Yes, it is enabled

No answers

Browser other questions tagged

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