Domanda

I am working on a php project where I want to find and store 3 cities in 100 KM range from a specified location into my database. I was thinking Google API Geocoding for this. I don't whether I'll be able to use it or not. But I found a line in Terms and Conditions page for Geocoding API that

the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.

What does it mean? Can I use the API for fetching the cities? Do anyone have any idea?

È stato utile?

Soluzione

It seems to me that this is very clear:

Yes you can use the Geocoding API if you will show nearest cities on Google map.

No, you can not use the Geocoding API if you will not show nearest cities on Google map.

There is no difference if you will store results and use it later.

btw. note that Yahoo have same usage policy.

Update: You can use GeoNames look here

Altri suggerimenti

I've written a code snippet that allows you to retrieve all nearby cities by combining the Google Maps Geocoding API and GeoNames.org API (besides a file_get_contents your could also do a cURL request).

/*
 * Get cities based on city name and radius in KM
 */

// get geocode object as array from The Google Maps Geocoding API
$geocodeObject = json_decode(file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address={CITY NAME},{COUNTRY CODE}'), true);

// get latitude and longitude from geocode object
$latitude = $geocodeObject['results'][0]['geometry']['location']['lat'];
$longitude = $geocodeObject['results'][0]['geometry']['location']['lng'];

// set request options
$responseStyle = 'short'; // the length of the response
$citySize = 'cities15000'; // the minimal number of citizens a city must have
$radius = 30; // the radius in KM
$maxRows = 30; // the maximum number of rows to retrieve
$username = '{YOUR USERNAME}'; // the username of your GeoNames account

// get nearby cities based on range as array from The GeoNames API
$nearbyCities = json_decode(file_get_contents('http://api.geonames.org/findNearbyPlaceNameJSON?lat='.$latitude.'&lng='.$longitude.'&style='.$responseStyle.'&cities='.$citySize.'&radius='.$radius.'&maxRows='.$maxRows.'&username='.$username, true));

// foreach nearby city get city details
foreach($nearbyCities->geonames as $cityDetails)
{
    // do something per nearby city
}

be carefull with your requests amount because the API's are limited

For more information about the API's visit the following url's:

It all boils down to what you want to achieve. Since you still need to use a database to store this location, would it not be better to obtain and store the data (lat and long) of the area your application seeks to cover in the database.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top