Is it possible to add personal sites to the google maps v3 autocomplete?

Asked

Viewed 130 times

6

I wanted to use the search of Google addresses but also wanted to introduce some personal areas. In the div which is generated by google I can add the fields I want, but I can’t create a function in click because there must be something in the google api that blocks the click. Below the code I used to add to the search:

   $(".pac-container").append('<div id="areasearch' + e + '" class="pac-item areasearch" style="display:none" onclick="clickOneAreaLocalizar(\'' + $(this).text() + '\')"><span class="pac-icon pac-icon-areas"></span><span class="pac-item-query"><span class="pac-matched"></span>' + $(this).text() + '</span> <span>Area</span></div>');

Upshot:inserir a descrição da imagem aqui

This is the code to add the query to the input:

   var input = /** @type {HTMLInputElement} */(document.getElementById('TextBoxPesquisaMaps')); 

 var searchBox = new google.maps.places.Autocomplete(/** @type {HTMLInputElement} */(input),  { types: ['geocode'] });

// Listen for the event fired when the user selects an item from the
// pick list. Retrieve the matching places for that item.
 google.maps.event.addListener(searchBox, 'place_changed', function () { 
            var places = searchBox.getPlace(); 

            // For each place, get the icon, place name, and location.

            var bounds = new google.maps.LatLngBounds();

            bounds.extend(places.geometry.location);
            localizarMaisProximo(places.geometry.location);

            map.fitBounds(bounds); 

 });

I made this example to better understand. jsfiddle when pressing qwerty makes an alert.

Does anyone have any idea how to do this? Thank you.

  • Reading the documentation, it doesn’t say anything that you can add your own places, no matter how much you add to the site in the combobox, it doesn’t have the data that the map needs to mark. I don’t think it’s possible right now.

1 answer

1

  • Good idea!! but I was left with some doubts if it works. When it says "You must create the markers and add them to the map" is it by code or add to the google online map available to everyone? I created an example in code and the milestones do not appear to me to be able to select. https://jsfiddle.net/14hthctd/

  • It’s by code, by the JS API of Maps, but it will only appear on your site... If you want to add to all who use Maps, just follow this article: https://support.google.com/maps/answer/6320846

  • The idea is to create by code to be dynamic. I’ll try some more tests, but the first one didn’t work :/

Browser other questions tagged

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