I suspect the problem comes from your creating a XML document, and
specifying headers for it after content has been created. Might I suggest
you drop the XML stuff until the very end if you really need it, and
instead fill an array with your results returned from SQL, then use the
array to create your output format: this could be JSON or XML or something
else you may require. Something like this:

[code]<?php

  require("connect.php");

  // Get parameters from URL - these should be cleaned before use here!!!
  // Example:  $center_lat = MyCleaningFunction($_GET["lat"]);
  $center_lat = $_GET["lat"];
  $center_lng = $_GET["lng"];
  $radius = $_GET["radius"];

  // Opens a connection to a mySQL server
  $connection=mysql_connect (localhost, $username, $password);
  if (!$connection) {
    die("Not connected : " . mysql_error());
  }
  // Set the active mySQL database
  $db_selected = mysql_select_db($database, $connection);
  if (!$db_selected) {
    die ("Can\'t use db : " . mysql_error());
  }
  // Search the rows in the markers table
  $query = sprintf("SELECT id, name, address, lat, lng, ( 3959 * acos( cos(
                    radians('%s') ) * cos( radians( lat ) ) * cos( radians(
lng ) -
                    radians('%s') ) + sin( radians('%s') ) * sin( radians(
lat ) ) ) ) AS
                    distance FROM markers HAVING distance < '%s' ORDER BY
distance LIMIT 0, 20",
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));
  $result = mysql_query($query);
  if (!$result) {
    die("Invalid query: " . mysql_error());
  }

  // Iterate through the rows, adding to array for each
  $retVal = array();
  while ($row = @mysql_fetch_assoc($result)){
    $retVal[] = array(  "id"        => $row['id'],
                        "name"      => $row['name'],
                        "address"   => $row['address'],
                        "lat"       => $row['lat'],
                        "lng"       => $row['lng'],
                        "distance"  => $row['distance']  );
  }

  // Return as JSON
  $json = json_encode($retVal);
  return $json;

  // Return as XML...
  // Refer to e.g.
http://stackoverflow.com/questions/1397036/how-to-convert-array-to-simplexml
  // for various ways to do this. No need to create a new document with
headers, etc....
  $xml = MyArrayToXMLConverter($retVal);

?>[/code]

HTH, Rob


On Wed, Apr 26, 2017 at 8:30 AM, <google-maps-js-api-v3@googlegroups.com>
wrote:

> google-maps-js-api-v3@googlegroups.com
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/google-maps-js-api-v3/topics>
>  Google
> Groups
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
> Topic digest
> View all topics
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/google-maps-js-api-v3/topics>
>
>    - GOOGLE MAP GOECODE <#m_-7307087608597225580_group_thread_0> - 1
>    Update
>
> GOOGLE MAP GOECODE
> <http://groups.google.com/group/google-maps-js-api-v3/t/9aa4c11bd5028e2c?utm_source=digest&utm_medium=email>
> Madhu Kumari <mk3469...@gmail.com>: Apr 22 04:06AM -0700
>
> i used this code but this is not give output,
>
> its only give error msg:
> This page contains the following errors:
> error on line 2 at column 1: Extra content at the end of the document
> Below is a rendering of the page up to the first error.
>
> <?php
> require("connect.php");
> // Get parameters from URL
> $center_lat = $_GET["lat"];
> $center_lng = $_GET["lng"];
> $radius = $_GET["radius"];
> // Start XML file, create parent node
> $dom = new DOMDocument("1.0");
> $node = $dom->createElement("markers");
> $parnode = $dom->appendChild($node);
> // Opens a connection to a mySQL server
> $connection=mysql_connect (localhost, $username, $password);
> if (!$connection) {
> die("Not connected : " . mysql_error());
> }
> // Set the active mySQL database
> $db_selected = mysql_select_db($database, $connection);
> if (!$db_selected) {
> die ("Can\'t use db : " . mysql_error());
> }
> // Search the rows in the markers table
> $query = sprintf("SELECT id, name, address, lat, lng, ( 3959 * acos( cos(
> radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) -
> radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS
> distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 ,
> 20",
> mysql_real_escape_string($center_lat),
> mysql_real_escape_string($center_lng),
> mysql_real_escape_string($center_lat),
> mysql_real_escape_string($radius));
> $result = mysql_query($query);
> $result = mysql_query($query);
> if (!$result) {
> die("Invalid query: " . mysql_error());
> }
> header("Content-type: text/xml");
> // Iterate through the rows, adding XML nodes for each
> while ($row = @mysql_fetch_assoc($result)){
> $node = $dom->createElement("marker");
> $newnode = $parnode->appendChild($node);
> $newnode->setAttribute("id", $row['id']);
> $newnode->setAttribute("name", $row['name']);
> $newnode->setAttribute("address", $row['address']);
> $newnode->setAttribute("lat", $row['lat']);
> $newnode->setAttribute("lng", $row['lng']);
> $newnode->setAttribute("distance", $row['distance']);
> }
> echo $dom->saveXML();
> ?>
>
>
>
>
>
> PLEASE HELP.
> Back to top <#m_-7307087608597225580_digest_top>
> You received this digest because you're subscribed to updates for this
> group. You can change your settings on the group membership page
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/google-maps-js-api-v3/join>
> .
> To unsubscribe from this group and stop receiving emails from it send an
> email to google-maps-js-api-v3+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-maps-js-api-v3+unsubscr...@googlegroups.com.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
Visit this group at https://groups.google.com/group/google-maps-js-api-v3.
For more options, visit https://groups.google.com/d/optout.
  • Re: [Google Maps API v3] ... 'Rob Banfield' via Google Maps JavaScript API v3

Reply via email to