php - Dynamic relation between GOOGLE Maps API v3 and MySQL -


i designing own first web page. it's real estate page users add open house information while others can pull info. code database , web (after 2 months...) , inserting , getting data sweet... google maps. trying have trulia or original housingmaps.com (it seems started mash up, right?). crimereports.com nice, too.

goal: pull addresses database, long , lat geocode, insert table, display in google map. plus: people pan map, new info pops map.

here code retrieving addresses, geo code, , add lat , lng database.

<?php //require("phpsqlajax_dbinfo.php");  // opens connection mysql server $username = "abc"; //personal info changed abc $password = "abc"; $hostname = "abc";  $database = "abc"; $connection = mysqli_connect($hostname, $username, $password); if (mysqli_connect_errno()) {     printf("connect failed: %s\n", mysqli_connect_error());     exit(); }  //if (!$connection) {   //die("not connected : " . mysql_error()); //}  define("maps_host", "maps.google.com"); define("key", "my .............key........code");    // set active mysql database $db_selected = mysqli_select_db($connection, $database); if (!$db_selected) {   die("can\'t use db : " . mysql_error()); }  // select rows in markers table $query = "select * brokerstour.property 1"; $result = mysqli_query($connection, $query); if (!$result) {   die("invalid query: " . mysql_error()); }  // initialize delay in geocode speed $delay = 0; $base_url = "http://maps.googleapis.com/maps/api/geocode/output?parameters";  // iterate through rows, geocoding each address while ($row = @mysqli_fetch_assoc($result)) {   $geocode_pending = true;    while ($geocode_pending) {     $address = $row["address"];     $id = $row["id"];     $request_url = $base_url . "&q=" . urlencode($address);     $xml = simplexml_load_file($request_url) or die("url not loading");      $status = $xml->response->status->code;     if (strcmp($status, "200") == 0) {       // successful geocode       $geocode_pending = false;       $coordinates = $xml->response->placemark->point->coordinates;       $coordinatessplit = split(",", $coordinates);       // format: longitude, latitude, altitude       $lat = $coordinatessplit[1];       $lng = $coordinatessplit[0];        $query = sprintf("update property " .              " set lat = '%s', lng = '%s' " .              " id = '%s' limit 1;",              mysql_real_escape_string($lat),              mysql_real_escape_string($lng),              mysql_real_escape_string($id));       $update_result = mysql_query($query);       if (!$update_result) {         die("invalid query: " . mysql_error());       }     } else if (strcmp($status, "620") == 0) {       // sent geocodes fast       $delay += 100000;     } else {       // failure geocode       $geocode_pending = false;       echo "address " . $address . " failed geocoded. ";       echo "received status " . $status . " \n";     }     usleep($delay);   } } ?> 

here have changed google tutorial (original code): 1) updated php: mysqli avoid errors. not getting more php errors. 2) changed url "http://" . maps_host . "/maps/geo?output=xml" . "&key=" . key; "http://maps.googleapis.com/maps/api/geocode/output?parameters" trying update code api v3.

if use old url, error 610. new url get:


( ! ) scream: error suppression ignored ( ! ) warning: simplexml_load_file(): i/o warning : failed load external entity "maps.googleapis.com/maps/api/geocode/output?parameters&q=4200+park+blvd+" in c:.... on line 57 .....

url not loading

full disclosure: new , maybe above doesn't make sense. have been stuck on problem week. (by way new google maps, book beginning google api 3 must. not deal database though, explains google maps api well).

could please give hint, book, tutorial? great help. thank time.

line 57 $xml = simplexml_load_file($request_url) or die("url not loading");

the $base_url = "http://maps.googleapis.com/maps/api/geocode/output?parameters"; not specify output.it should either xml or jason. parameters pass address , either sensor = false or sensor = true

edit

remove

$geocode_pending = true; while ($geocode_pending) { 

end edit

$q = $row["address"]; $base_url = "http://maps.googleapis.com/maps/api/geocode/xml?address="; $request_url = $base_url.urlencode($q)."&sensor=false"; $xml = simplexml_load_file($request_url) or die("url not loading"); if($xml->status=="ok"){     // successful geocode     $lat = $xml->result->geometry->location->lat;     $lng = $xml->result->geometry->location->lng;  

edit

    echo $lat.","$lng."<br>";//     }      } 

remove rest of code , make sure works before incementally adding rest of code


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -