Using PHP/MySQL with Google Maps with Autocomplete searchbox -


i using https://developers.google.com/maps/articles/phpsqlajax_v3

    <!doctype html >   <head>     <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>     <title>consultants map</title>     <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>     <script type="text/javascript">     //<![cdata[      var customicons = {       restaurant: {         icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',         shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'       },       bar: {         icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',         shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'       }     };      function load() {       var map = new google.maps.map(document.getelementbyid("map"), {         center: new google.maps.latlng(46.80, -100.78),         zoom: 4,         maptypeid: 'roadmap'       });       var infowindow = new google.maps.infowindow;        //autocomplete.bindto('bounds', map);        // change depending on name of php file       downloadurl("consultants_maps.php", function(data) {         var xml = data.responsexml;         var markers = xml.documentelement.getelementsbytagname("marker");         (var = 0; < markers.length; i++) {           var name = markers[i].getattribute("name");           var address = markers[i].getattribute("address");           var type = markers[i].getattribute("type");           var point = new google.maps.latlng(               parsefloat(markers[i].getattribute("lat")),               parsefloat(markers[i].getattribute("lng")));                 var html = "<b>" + name + "</b> <br/>"  + address;            var icon = customicons[type] || {};           var marker = new google.maps.marker({             map: map,             position: point,             icon: icon.icon,             shadow: icon.shadow           });           bindinfowindow(marker, map, infowindow, html);         }       });     }      function bindinfowindow(marker, map, infowindow, html) {       google.maps.event.addlistener(marker, 'click', function() {         infowindow.setcontent(html);         infowindow.open(map, marker);       });     }      function downloadurl(url, callback) {       var request = window.activexobject ?           new activexobject('microsoft.xmlhttp') :           new xmlhttprequest;        request.onreadystatechange = function() {         if (request.readystate == 4) {           request.onreadystatechange = donothing;           callback(request, request.status);         }       };        request.open('get', url, true);       request.send(null);     }      function donothing() {}      //]]> </script></head><body onload="load()">     <div id="map" style="width: 1280px; height: 720px"></div>   </body> </html> 

also here php code that:

<?php require_once('wp-config.php'); require_once('wp-load.php'); require_once('wp-includes/wp-db.php');      global $wpdb;     $table_name     = $wpdb->prefix . "consultants_map";  $dom = new domdocument("1.0"); $node = $dom->createelement("markers"); $parnode = $dom->appendchild($node);   $query = "select * $table_name 1"; $result = mysql_query($query);  header("content-type: text/xml");   // iterate through rows, adding xml nodes each  while ($row = @mysql_fetch_assoc($result)){     // add xml document node     $address = $row['kt_number'] . "<br />" . $row['address'];   $node = $dom->createelement("marker");     $newnode = $parnode->appendchild($node);      $newnode->setattribute("name",$row['name']);   $newnode->setattribute("address", $address);     $newnode->setattribute("lat", $row['lat']);     $newnode->setattribute("lng", $row['lng']);     //$newnode->setattribute("type", $row['type']); }   echo $dom->savexml();  ?> 

its working fine me

but want add here autocomplete text box feature https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete

how can combine both code in single place???

please me.

thanks

by following exact example linked @ https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete can notice critical bits missing:

  1. add places libraries when loading library (https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places)
  2. create autocomplete objects var autocomplete = new google.maps.places.autocomplete(document.getelementbyid('searchtextfield'));
  3. autocomplete.bindto('bounds', map); , bind

taking care of above should allow functionality through.

you should add event listener google.maps.event.addlistener(autocomplete, 'place_changed', function() { ... triggered when place changed, , autocomplete.getplace() place object contains lots of information on place chosen. follow example in link found more details , examples.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -