Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to integrate SearchBox in Google Maps JavaScript API v3?
    primarykey
    data
    text
    <p>I would like to create a google map with search box on top like on this side: <a href="https://google-developers.appspot.com/maps/documentation/javascript/examples/places-searchbox" rel="nofollow noreferrer">https://google-developers.appspot.com/...</a> with the JavaScript API v3.</p> <p>At the moment I use the following code to show a map by getting the latitude and longitude in the url (php get):</p> <pre><code>&lt;?php $latitude = $_GET['lat']; $longitude = $_GET['long']; ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; &lt;/script&gt; &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt; &lt;style type="text/css"&gt; html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } #search-panel { position: absolute; top: 5px; left: 50%; margin-left: -180px; width: 350px; z-index: 5; background-color: #fff; padding: 5px; border: 1px solid #999; } #target { width: 345px; } &lt;/style&gt; &lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXX&amp;sensor=true"&gt; &lt;/script&gt; &lt;script type="text/javascript"&gt; function initialize() { var input = document.getElementById('searchTextField'); var image = 'pin.png'; var myLatlng = new google.maps.LatLng(&lt;?php echo "$latitude" ?&gt;, &lt;?php echo "$longitude" ?&gt;); var mapOptions = { center: myLatlng, zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP, streetViewControl: true, }; var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); var marker = new google.maps.Marker({ icon: image, position: myLatlng, map: map, animation: google.maps.Animation.DROP, title:"You Location" }); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="initialize()"&gt; &lt;div id="map_canvas" style="width:100%; height:100%"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>But I don't get it, to integrate the Search Box like on the named site!!!</p> <p>Can someone help?</p> <hr> <p>I edited the code to this, but I doesn't work!:</p> <pre><code>&lt;?php $latitude = $_GET['lat']; $longitude = $_GET['long']; ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt; &lt;style type="text/css"&gt; html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } #search-panel { position: absolute; top: 5px; left: 50%; margin-left: -180px; width: 350px; z-index: 5; background-color: #fff; padding: 5px; border: 1px solid #999; } #target { width: 345px; } &lt;/style&gt; &lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXX&amp;sensor=true"&gt; &lt;/script&gt; &lt;script type="text/javascript"&gt; function initialize() { var searchBox = new google.maps.places.SearchBox(input, { bounds: defaultBounds // have to be defined first }); google.maps.event.addListener(searchBox, 'places_changed', function() { var places = searchBox.getPlaces(); // do your stuff here var input = document.getElementById('searchTextField'); var image = 'pin.png'; var myLatlng = new google.maps.LatLng(&lt;?php echo "$latitude" ?&gt;, &lt;?php echo "$longitude" ?&gt;); var mapOptions = { center: myLatlng, zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP, streetViewControl: true, }; var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); var marker = new google.maps.Marker({ icon: image, position: myLatlng, map: map, animation: google.maps.Animation.DROP, title:"You Location" var input = document.getElementById('target'); var searchBox = new google.maps.places.SearchBox(input); var markers = []; google.maps.event.addListener(searchBox, 'places_changed', function() { var places = searchBox.getPlaces(); }); }); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="initialize()"&gt; &lt;div id="search-panel"&gt; &lt;input id="target" type="text" placeholder="Search Box"&gt; &lt;/div&gt; &lt;div id="map_canvas" style="width:100%; height:100%"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload