Rectangle 27 5

Maybe you are sending too many queries per second?

php - Google Maps Geocode Status OVER_QUERY_LIMIT - Stack Overflow

php google-maps geolocation geocoding
Rectangle 27 4

The quota is shared among all the users of the shared IP, so other sites on the same shared IP must be using the Google Geocoder.

BTW - rackspace was a guess...

A workaround would be to use client based geocoding, but verify your use complies with the terms of use.

The webservice now supports a key, another option is to use a key in your request so you get your own quota.

php - Google Maps Geocode Status OVER_QUERY_LIMIT - Stack Overflow

php google-maps geolocation geocoding
Rectangle 27 1

I faced a similar issue to this with my heroku hosted java application. The way I got around it was to set up a micro EC2 instance and install Dante on it to run as a proxy server. Then I just route my gecoding requests through the proxy and can make the full 2,000 requests per day. Obviously it's worth caching results to minimise the api calls too. The EC2 instance is free for the first year and after that still not that expensive and you can always use it for more than just Dante.

php - Google Maps Geocode Status OVER_QUERY_LIMIT - Stack Overflow

php google-maps geolocation geocoding
Rectangle 27 31

<?php
  $Address = urlencode($Address);
  $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$Address."&sensor=true";
  $xml = simplexml_load_file($request_url) or die("url not loading");
  $status = $xml->status;
  if ($status=="OK") {
      $Lat = $xml->result->geometry->location->lat;
      $Lon = $xml->result->geometry->location->lng;
      $LatLng = "$Lat,$Lon";
  }
?>

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

Google Maps - converting address to latitude & longitude - PHP backend...

php google-maps geocoding
Rectangle 27 3

When you are sending request from php the request will sent from you server IP and the google allows limited request for single ip, so it's better to send request from user's IP. You can do it by using below JavaScript function.

function display_map(address_str,business_name,phone_number,google_local_pages){

var address = address_str;

// Create a new Geocoder
var geocoder = new google.maps.Geocoder();

// Locate the address using the Geocoder.
    geocoder.geocode( { "address": address }, function(results, status) {

      // If the Geocoding was successful
      if (status == google.maps.GeocoderStatus.OK) {

          var latlang = results[0].geometry.location;
    //      alert(latlang);

        // Create a Google Map at the latitude/longitude returned by the Geocoder.
        var myOptions = {
          zoom: 16,
          center: results[0].geometry.location,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map"), myOptions);

        // Add a marker at the address.
        var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
        });

     //   var data = "<div id='top'><span>"+business_name+"</span><a href='"+google_local_pages+"'>More Info</a><div id='address'>"+address_str+"</div></div>";

        var infowindow = new google.maps.InfoWindow({
        content: "<div id='top' style='height:175px;width:200px;'><span id='bname' style='font-size: 1.3em;font-weight:bold;'>"+business_name+':'+"</span><a style='text-decoration: none;' target='_blank' href='"+google_local_pages+"'>More Info</a><hr/><div id='address' style='font-size: 1em;font-weight:normal;align:left'>"+address_str+"</div><hr/><div id='lower'><a style='text-decoration: none;' target='blank' href='http://maps.google.com/maps?saddr=&daddr="+address_str+"'"+">Directions</a>&emsp;<a style='text-decoration: none;' href='javascript:void(0);' onclick='showform();'>Search Nearby</a><div style='display:none;' id='hiddenForm'><hr><span style='font-size: 1em;font-weight:bold;'>Search Nearby:</span><form action='http://maps.google.com/maps' method='get' target='_blank'><input type='text' name='q' id='q' value='' size='12' /><input type='submit' value='GO'/>&emsp;<span phv='&quot;%1$s&quot;' style='font-size: 0.7em;font-weight: small;'>e.g.,&ldquo;pizza&ldquo;</span><input type='hidden' name='near' value='"+address_str+"'/></form></div></div>"
        });

        google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map, marker);
            });

      } else {
        try {
          console.error("Geocode was not successful for the following reason: " + status);
        } catch(e) {}
      }
    });
}

geocoding - Google Maps V3 API - Over Query Limit, but just 1 request ...

google-maps geocoding
Rectangle 27 7

<?php

/* 
* Given an address, return the longitude and latitude using The Google Geocoding API V3
*
*/

function Get_LatLng_From_Google_Maps($address) {
    $address = urlencode($address);

    $url = "http://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=false";

    // Make the HTTP request
    $data = @file_get_contents($url);
    // Parse the json response
    $jsondata = json_decode($data,true);

    // If the json data is invalid, return empty array
    if (!check_status($jsondata))   return array();

    $LatLng = array(
        'lat' => $jsondata["results"][0]["geometry"]["location"]["lat"],
        'lng' => $jsondata["results"][0]["geometry"]["location"]["lng"],
    );

    return $LatLng;
}

/* 
* Check if the json data from Google Geo is valid 
*/

function check_status($jsondata) {
    if ($jsondata["status"] == "OK") return true;
    return false;
}

/*
*  Print an array
*/

function d($a) {
    echo "<pre>";
    print_r($a);
    echo "</pre>";
}

Google Maps - converting address to latitude & longitude - PHP backend...

php google-maps geocoding
Rectangle 27 1

<?php
$address = "Kathmandu, Nepal";
$url = "http://maps.google.com/maps/api/geocode/json?address=".urlencode($address);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
$responseJson = curl_exec($ch);
curl_close($ch);

$response = json_decode($responseJson);

if ($response->status == 'OK') {
    $latitude = $response->results[0]->geometry->location->lat;
    $longitude = $response->results[0]->geometry->location->lng;

    echo 'Latitude: ' . $latitude;
    echo '<br />';
    echo 'Longitude: ' . $longitude;
} else {
    echo $response->status;
    var_dump($response);
}    
?>

google maps - PHP - Get Latitude & Longitude from an address - Stack O...

php google-maps google-geocoder
Rectangle 27 3

You'll have to use the Geocoder API.

Here you go ( original can be found here ) :

<head>
...
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();

    var mapOptions = {
      zoom: 12, //Change the Zoom level to suit your needs
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    //map_canvas is just a <div> on the page with the id="map_canvas"
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

    //Your Variable Containing The Address
    var address = "<?php echo $AddressVariable; ?>"; 
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        //places a marker on every location
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert('Geocode was not successful for the following reason: ' + status);
      }
    });

  }

</script>
...
</head>

Add this to the opening body tag of your page to initialize the map:

<body onload="initialize()">

And here's the documentation for the Geocoder class.

Address in PHP variable, Google Maps embedding without Javascript? - S...

php google-maps geocoding
Rectangle 27 3

You'll have to use the Geocoder API.

Here you go ( original can be found here ) :

<head>
...
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();

    var mapOptions = {
      zoom: 12, //Change the Zoom level to suit your needs
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    //map_canvas is just a <div> on the page with the id="map_canvas"
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

    //Your Variable Containing The Address
    var address = "<?php echo $AddressVariable; ?>"; 
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        //places a marker on every location
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert('Geocode was not successful for the following reason: ' + status);
      }
    });

  }

</script>
...
</head>

Add this to the opening body tag of your page to initialize the map:

<body onload="initialize()">

And here's the documentation for the Geocoder class.

Address in PHP variable, Google Maps embedding without Javascript? - S...

php google-maps geocoding
Rectangle 27 5

<?php

/* 
* Given longitude and latitude in North America, return the address using The Google Geocoding API V3
*
*/

function Get_Address_From_Google_Maps($lat, $lon) {

$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lon&sensor=false";

// Make the HTTP request
$data = @file_get_contents($url);
// Parse the json response
$jsondata = json_decode($data,true);

// If the json data is invalid, return empty array
if (!check_status($jsondata))   return array();

$address = array(
    'country' => google_getCountry($jsondata),
    'province' => google_getProvince($jsondata),
    'city' => google_getCity($jsondata),
    'street' => google_getStreet($jsondata),
    'postal_code' => google_getPostalCode($jsondata),
    'country_code' => google_getCountryCode($jsondata),
    'formatted_address' => google_getAddress($jsondata),
);

return $address;
}

/* 
* Check if the json data from Google Geo is valid 
*/

function check_status($jsondata) {
    if ($jsondata["status"] == "OK") return true;
    return false;
}

/*
* Given Google Geocode json, return the value in the specified element of the array
*/

function google_getCountry($jsondata) {
    return Find_Long_Name_Given_Type("country", $jsondata["results"][0]["address_components"]);
}
function google_getProvince($jsondata) {
    return Find_Long_Name_Given_Type("administrative_area_level_1", $jsondata["results"][0]["address_components"], true);
}
function google_getCity($jsondata) {
    return Find_Long_Name_Given_Type("locality", $jsondata["results"][0]["address_components"]);
}
function google_getStreet($jsondata) {
    return Find_Long_Name_Given_Type("street_number", $jsondata["results"][0]["address_components"]) . ' ' . Find_Long_Name_Given_Type("route", $jsondata["results"][0]["address_components"]);
}
function google_getPostalCode($jsondata) {
    return Find_Long_Name_Given_Type("postal_code", $jsondata["results"][0]["address_components"]);
}
function google_getCountryCode($jsondata) {
    return Find_Long_Name_Given_Type("country", $jsondata["results"][0]["address_components"], true);
}
function google_getAddress($jsondata) {
    return $jsondata["results"][0]["formatted_address"];
}

/*
* Searching in Google Geo json, return the long name given the type. 
* (If short_name is true, return short name)
*/

function Find_Long_Name_Given_Type($type, $array, $short_name = false) {
    foreach( $array as $value) {
        if (in_array($type, $value["types"])) {
            if ($short_name)    
                return $value["short_name"];
            return $value["long_name"];
        }
    }
}

/*
*  Print an array
*/

function d($a) {
    echo "<pre>";
    print_r($a);
    echo "</pre>";
}

Feel free to look at my blog for a sample code of how using the code above and sample result.

geolocation - PHP Latitude Longitude to Address - Stack Overflow

php geolocation location latitude-longitude
Rectangle 27 2

Geocode the address in your initialize function. Use the returned latitude and longitude to initialize the map.

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var geocoder;
var centerChangedLast;
var reverseGeocodedLast;
var currentReverseGeocodeResponse;

var geocoder = new google.maps.Geocoder();
var address = "<?php echo $address;?>";


function initialize() {
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      var latitude = results[0].geometry.location.lat();
      var longitude = results[0].geometry.location.lng();
      var latlng = new google.maps.LatLng(latitude,longitude);
      var myOptions = {
        zoom: 10,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
      geocoder = new google.maps.Geocoder();

      var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: "My Location"
      });

    } 
  });
}

</script>

Awesome! appreciate genius. have a good day

javascript - passing the latitude and longitude to my map script - Sta...

javascript google-maps google-api
Rectangle 27 3

Here is the solution,

<?php
    $lat = $_POST['lat'];
    $lng = $_POST['lng'];

    $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$lat.','.$lng.'&sensor=false';
    $json = @file_get_contents($url);
    $data = json_decode($json);
    $status = $data->status;
    if($status=="OK") {
        //Get address from json data
        for ($j=0;$j<count($data->results[0]->address_components);$j++) {
            $cn=array($data->results[0]->address_components[$j]->types[0]);
            if(in_array("locality", $cn)) {
                $city= $data->results[0]->address_components[$j]->long_name;
            }
        }
     } else{
       echo 'Location Not Found';
     }
     //Print city 
     echo $city;
for ($j=0;$j<count($data->results[0]->address_components);$j++) {
    $cn=array($data->results[0]->address_components[$j]->types[0]);
    if (in_array("locality", $cn)) {
        $city= $data->results[0]->address_components[$j]->long_name;
    }
}

best way to get city name from google reverse geocoding api php - Stac...

php google-maps reverse-geocoding
Rectangle 27 9

<?php
$address = 'BTM 2nd Stage, Bengaluru, Karnataka 560076'; // Address

// Get JSON results from this request
$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
$geo = json_decode($geo, true); // Convert the JSON to an array

if (isset($geo['status']) && ($geo['status'] == 'OK')) {
  $latitude = $geo['results'][0]['geometry']['location']['lat']; // Latitude
  $longitude = $geo['results'][0]['geometry']['location']['lng']; // Longitude
}?>

php - How to get longitude and latitude of any address? - Stack Overfl...

php
Rectangle 27 2

You really need to loop and do multiple checks of what google found at these points a small script to actually reads/loop the returned data would be (in PHP):

Now based on the documentation:

Note that the reverse geocoder returned more than one result. ...etc

Generally, addresses are returned from most specific to least specific; the more exact address is the most prominent result...etc

You only need the first result to get what you want (or at least to search for it there $data->results[0]->. So have a read of the types and based on that you can check if the result you want present or not:

<?php
$data = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=46.1124,1.245&sensor=true"));
if($data->status == "OK") {
    if(count($data->results)) {
        foreach($data->results[0]->address_components as $component) {
            if(in_array("premise",$component->types) || in_array("route",$component->types) || in_array("park",$component->types)) {
                echo $component->long_name . "<br />";
            }
        }
    }
} else {
    // error
}
?>

just wondering why this was a PHP solution and not a JS solution?

javascript - Reverse Geocoding with Google Map API - Stack Overflow

javascript google-maps geolocation reverse-geocoding
Rectangle 27 0

<?php
class latLngFinder {
    public $output;
    public $lat;
    public $lng;
    public $formatted_address;

    public function __construct($inputaddress)
    {
        $this->address = $inputaddress;
        $this->output = $this->findCoord();
    }

    /**
    * Creates cURL connection to Google API v3
    * @param string $url The URL to read from
    * @return string The URL content
    */
    private function getURL($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        $tmp = curl_exec($ch);
        curl_close($ch);
        if ($tmp != false){
            return $tmp;
        }
    }

    /**
    * Get Latitude/Longitude/Formatted Address based on an address
    * @param string $address The address for finding coordinates
    * @return array An array containing Latitude/Longitude/Formatted Address
    */
    private function findCoord(){
        $address = str_replace(' ', '+', $this->address);
        $url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=' . $address . '&sensor=false';
        $data = $this->getURL($url);
        if ($data){
            $xml = new SimpleXMLElement($data);
            $status = $xml->status;

            // Use this to debug returned XML
            //print_r($xml);

            if ($status == 'OK'){
                // Find Latitude/Longitude/Formatted Address in XML
                $lat = $xml->result->geometry->location->lat;
                $lng = $xml->result->geometry->location->lng;
                $formatted_addr = $xml->result->formatted_address;
                $this->lat = $lat;
                $this->lng = $lng;
                $this->formatted_address = $formatted_addr;
            }
        }
    }
}

// Initialise the latLngFinder class
$obj = new latLngFinder($row['address']);
echo $obj->lat;
echo "<br />";
echo $obj->lng;
echo "<br />";
echo $obj->formatted_address;
?>

PHP Notice: Undefined property: latLngFinder::$lat I guess the $lat variable needs to be declared? I don't really know how to do that

ok I don't get the error now but nothing is returned on screen.

sorry i was calling an incorrect function (copy and pasted from some of my code) try again slightly updated now

xml - Get returned array values from object into variable PHP - Stack ...

php xml database arrays object
Rectangle 27 0

Maybe you are sending too many queries per second?

php - Google Maps Geocode Status OVER_QUERY_LIMIT - Stack Overflow

php google-maps geolocation geocoding
Rectangle 27 0

You can use a hosted proxy service like QuotaGuard which will stop your requests coming from a shared IP so you don't get blocked by Google when using Rackspace/Heroku etc.

php - Google Maps Geocode Status OVER_QUERY_LIMIT - Stack Overflow

php google-maps geolocation geocoding
Rectangle 27 0

Maybe you are sending too many queries per second?

php - Google Maps Geocode Status OVER_QUERY_LIMIT - Stack Overflow

php google-maps geolocation geocoding
Rectangle 27 0

I have the same problem making calls to the geocoding REST interface from a server on Heroku (hosted on Amazon EC2)

This could be fixed if I could use my Maps API key in the request and they tracked the number of calls per api key.

I agree that this is a serious problem...

php - Google Maps Geocode Status OVER_QUERY_LIMIT - Stack Overflow

php google-maps geolocation geocoding
Rectangle 27 0

<?php
  $Address = urlencode($Address);
  $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$Address."&sensor=true";
  $xml = simplexml_load_file($request_url) or die("url not loading");
  $status = $xml->status;
  if ($status=="OK") {
      $Lat = $xml->result->geometry->location->lat;
      $Lon = $xml->result->geometry->location->lng;
      $LatLng = "$Lat,$Lon";
  }
?>

Google Maps - converting address to latitude & longitude - PHP backend...

php google-maps geocoding