Find by establishment and not by street GOOGLE MAPS

Asked

Viewed 177 times

0

I am using the following code to find streets on google maps, but I have the need to find establishments, here follows the link of the project, being having difficulties to find the sites.

var geocoder;
var map;
var marker; function initialize() {
    var latlng = new google.maps.LatLng(-18.8800397, -47.05878999999999);
    var options = {
        zoom: 5,
        center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP };
    map = new google.maps.Map(document.getElementById("mapa"), options);

geocoder = new google.maps.Geocoder();

marker = new google.maps.Marker({
    map: map,
    draggable: true,
});

marker.setPosition(latlng);}$(document).ready(function () { initialize();

function carregarNoMapa(endereco) {
    geocoder.geocode({ 'address': endereco + ', Brasil', 'region': 'BR' }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                var latitude = results[0].geometry.location.lat();
                var longitude = results[0].geometry.location.lng();

                $('#txtEndereco').val(results[0].formatted_address);
                $('#txtLatitude').val(latitude);
                $('#txtLongitude').val(longitude);

                var location = new google.maps.LatLng(latitude, longitude);
                marker.setPosition(location);
                map.setCenter(location);
                map.setZoom(16);
            }
        }
    })
}

$("#btnEndereco").click(function() {
    if($(this).val() != "")
        carregarNoMapa($("#txtEndereco").val());
})

$("#txtEndereco").blur(function() {
    if($(this).val() != "")
        carregarNoMapa($(this).val());
})

google.maps.event.addListener(marker, 'drag', function () {
    geocoder.geocode({ 'latLng': marker.getPosition() }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {  
                $('#txtEndereco').val(results[0].formatted_address);
                $('#txtLatitude').val(marker.getPosition().lat());
                $('#txtLongitude').val(marker.getPosition().lng());
            }
        }
    });
});

$("#txtEndereco").autocomplete({
    source: function (request, response) {
        geocoder.geocode({ 'address': request.term + ', Brasil', 'region': 'BR' }, function (results, status) {
            response($.map(results, function (item) {
                return {
                    label: item.formatted_address,
                    value: item.formatted_address,
                    latitude: item.geometry.location.lat(),
                    longitude: item.geometry.location.lng()
                }
            }));
        })
    },
    select: function (event, ui) {
        $("#txtLatitude").val(ui.item.latitude);
        $("#txtLongitude").val(ui.item.longitude);
        var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
        marker.setPosition(location);
        map.setCenter(location);
        map.setZoom(16);
    }
});

$("form").submit(function(event) {
    event.preventDefault();

    var endereco = $("#txtEndereco").val();
    var latitude = $("#txtLatitude").val();
    var longitude = $("#txtLongitude").val();

    alert("Endereço: " + endereco + "\nLatitude: " + latitude + "\nLongitude: " + longitude);
}); });
  • Where are these places? I don’t quite understand?

  • The script above is searching for street, I want to search for Places(Places). Ex: Hospital, shops etc. I left an example link, if possible do a search.

  • Give me an example of where to search.

  • Ex: Hospital 9 de Julho, Hospital Santa Casa, Hospital Campo Limpo

  • If you do it on Google maps, he thinks. I noticed that every time I search it auto complete, tries to disable auto complete and search for Hospital July 9

  • Had already tried this and did not work, to disable auto complete.

  • I have searched by (Hospital 9 de Julho) and leave (Ladeira do Hospital, 9 - Nazaré, Salvador - BA, 40050-420, Brazil)

  • Yes, because you’re looking for an address and not locations.

  • Friend, take all this off of self help. Probably if you search Sao Paulo Hospital as ADDRES, you will find.

  • I had already done it and it didn’t work, I changed the addres to Places and it didn’t work either.

  • Okay, if you just think by addres do the following, take all hospitals, put in an array with NAME + ADDRESS. when the person searches for XPTO HOSPITAL Voce goes in the array finds it by NAME retrieves the ADDRESS and looks for it.

  • In this case, it wouldn’t be possible, because I don’t have this list of hospitals, this research would be to feed my database.

  • 1

    Anything new?

  • Yes, I ended up using another Google api to do, soon I will post the code so you can take a look.

  • Nice guy, congratulations there @Henrique S. Santos

  • Have you tried using this http://gmap3.net script ? There is an example in the source code that does this, in the folder [examples] run [autocomplete] it works by locations and addresses. It can be a reference... that allows you to evolve with the solution.

Show 11 more comments
No answers

Browser other questions tagged

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