Unfortunately, it is not possible to get the place ID of a city or neighborhood directly from the Google Places API autocomplete response. However, you can use the place ID of the selected address to retrieve additional details about the place, including its address components such as the city and neighborhood.
Here's an example of how you can use the Google Places API Place Details request to retrieve the city and neighborhood of a selected address:
// Assuming you have the place ID of the selected address
$placeId = '...';
// Send a Place Details request to retrieve additional details about the place
$placeDetails = file_get_contents("https://maps.googleapis.com/maps/api/place/details/json?key=YOUR_API_KEY&place_id=$placeId");
// Parse the JSON response
$placeDetails = json_decode($placeDetails, true);
// Extract the city and neighborhood from the address components
$addressComponents = $placeDetails['result']['address_components'];
$city = null;
$neighborhood = null;
foreach ($addressComponents as $component) {
if (in_array('locality', $component['types'])) {
$city = $component['long_name'];
}
if (in_array('neighborhood', $component['types'])) {
$neighborhood = $component['long_name'];
}
}
// Now you can use the city and neighborhood to compare with your database
Note that you will need to replace YOUR_API_KEY with your actual Google Places API key. Also, keep in mind that the address components returned by the API may vary depending on the location and the type of address.