7 Replies - 716 Views - Last Post: 16 January 2016 - 11:42 PM

#1 tsutomu197   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 15

my google api search box does not work properly

Posted 16 January 2016 - 04:01 PM

hi I have made a google map with the api and added a search box
it works but no matter what zip/address I type on it, it sends me to some weird
coordinates, here is what I have and it all works well, except for the search box.

function initAutocomplete() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 39.790117, lng: -96.584307},
    zoom: 4,
    scrollwheel: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  var input = document.getElementById('pac-input');
  var searchBox = new google.maps.places.SearchBox(input,null);
  google.maps.event.addListener(searchBox,'places_changed', function() {
     var places = searchBox.getPlaces();
     var bounds = new google.maps.LatLngBounds();
     map.fitBounds(bounds);
     map.getPlaces(input);
  });



Is This A Good Question/Topic? 0
  • +

Replies To: my google api search box does not work properly

#2 andrewsw   User is online

  • never lube your breaks
  • member icon

Reputation: 6833
  • View blog
  • Posts: 28,342
  • Joined: 12-December 12

Re: my google api search box does not work properly

Posted 16 January 2016 - 04:17 PM

Are there any errors in your browser's console?

It would be helpful if you posted a link to the example you are following.

One thing that stands out is that you don't do anything with your 'places' variable.
Was This Post Helpful? 0
  • +
  • -

#3 tsutomu197   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 15

Re: my google api search box does not work properly

Posted 16 January 2016 - 04:22 PM

Im sorry but no errors, like I said the only problem Im having is that everytime I search a zipcode/state the search sends me to the middle of the indian ocean, I tried changing the LatLng and that give me an undefine error. Im still working on it as we speak.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is online

  • never lube your breaks
  • member icon

Reputation: 6833
  • View blog
  • Posts: 28,342
  • Joined: 12-December 12

Re: my google api search box does not work properly

Posted 16 January 2016 - 04:30 PM

Presumably you are following an example, some template? So, as requested, post a link to it.
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3065
  • View blog
  • Posts: 11,759
  • Joined: 03-December 12

Re: my google api search box does not work properly

Posted 16 January 2016 - 05:18 PM

Where did you get the lat and longitude you are currently using? What does the search box do? You can build an address to send to the API that will return coordinates for that address.
Was This Post Helpful? 0
  • +
  • -

#6 tsutomu197   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 15

Re: my google api search box does not work properly

Posted 16 January 2016 - 07:54 PM

here i fixed it sorry for not posting the rest but is all default settings

function initAutocomplete() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 39.790117, lng: -96.584307},
    zoom: 4,
    scrollwheel: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  var input = document.getElementById('pac-input');
  var searchBox = new google.maps.places.SearchBox(input,null);
  google.maps.event.addListener(searchBox,'places_changed', function() {
     var places = searchBox.getPlaces();
     var bounds = new google.maps.LatLngBounds();
     for(i=0; place=places[i]; i++){
      bounds.extend(place.geometry.location);
     }
     map.fitBounds(bounds);
     map.setZoom(12);
  });

Was This Post Helpful? 0
  • +
  • -

#7 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3065
  • View blog
  • Posts: 11,759
  • Joined: 03-December 12

Re: my google api search box does not work properly

Posted 16 January 2016 - 08:16 PM

First thing I would suggest is to change the starting lat and long to the location you actually want centered, that will make a difference.
Was This Post Helpful? 1
  • +
  • -

#8 tsutomu197   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-March 15

Re: my google api search box does not work properly

Posted 16 January 2016 - 11:42 PM

well is set that way, because I want to open showing the USA, it displays markers with information about golf courses around the US,right now trying to display that info on the bottom of the map on a box
or may be ill try appending it to a <div id='infowindow'>.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1