Whats the difference between location and viewport coordinates when geocoding with google API v3 - google-maps

I am new with using the Google maps geocoding API. I gave it an address and have a few different coordinates in the response. Why are there different coordinates?

More on Viewports: https://developers.google.com/maps/documentation/geocoding/intro#Viewports
"In a geocoding request, you can instruct the Geocoding service to prefer results within a given viewport (expressed as a bounding box). You do so within the request URL by setting the bounds parameter. Note that biasing only prefers results within the bounds; if more relevant results exist outside of these bounds, they may be included.
The bounds parameter defines the latitude/longitude coordinates of the southwest and northeast corners of this bounding box using a pipe (|) character to separate the coordinates."
Viewport allows you to create a boundary within a specific region, sort of like looking at a larger section of the map within a set of coordinates. Locations coordinates are giving you the exact spot of a location.

Related

Using bounds to search for coordinates

I try to create a google maps API call that searches an address in a specific boundary.
So in my test I want to search for "8670" which is a postal code from a village in Belgium. This village:
https://www.google.com/maps/place/8670+Koksijde,+Belgium/#51.1129798,2.6459201,13z/data=!3m1!4b1!4m5!3m4!1s0x47dcba8d702c832d:0x10129f1eb06df0d2!8m2!3d51.117577!4d2.6744402
Using the country-parameter in the API call gives me the right answer:
https://maps.googleapis.com/maps/api/geocode/json?address=8670|country:BE
But using the bounds-parameter returns me a city in the USA:
https://maps.googleapis.com/maps/api/geocode/json?address=8670&bounds=53.6014224,7.0979623|49.4057287,2.4896213
I know bounds is not a strict filter, but as there is a city in range of the bounds with that postal code leaves me with the question why does google not find it and return me a city far away from my bounds?
The reason why I want to use bounds and not country-parameter is because the search is for 3 countries (NL, BE, LU) and as far as I know it is not possible to use OR in the country-parameter.
The documentation says that bounds parameter defines the latitude/longitude coordinates of the southwest and northeast corners of this bounding box.
https://developers.google.com/maps/documentation/geocoding/intro#Viewports
So, the first coordinate should be coordinate of southwest and second coordinate should be coordinate of northeast. In you example you define bounds in opposite order NE|SW. Just swap values in bounds parameter and you will have expected result '8670 Koksijde, Belgium' (place ID ChIJLYMscI263EcR0vBtsB6fEhA):
https://maps.googleapis.com/maps/api/geocode/json?address=8670&bounds=49.4057287%2C2.4896213%7C53.6014224%2C7.0979623&key=YOUR_API_KEY
or
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A8670&bounds=49.4057287%2C2.4896213%7C53.6014224%2C7.0979623&key=YOUR_API_KEY
I hope this helps!

Get alle coordinates within an area - Google Maps

I've made a website using the geolocation API, which shows if you're in Berlin or not. To get alle the coordinates I've selected Berlin in Google Maps and downloaded a KML file with these coordinates.
Now I would like to have all the coordinates within that selection, because in the KML file are only the coordinates of the border.
Is this possible?
Get all the coordinates within an area doesn't make sense because there are literally infinite coordinates within a polygon (depending on the resolution of your coordinates of course).
What you need is to check wheter a given point is contained within a polygon. You can do it using the containsLocation() method (see the documentation)

Find cafes within certain distance of location from Google Maps

I am using the textSearchQuery method of PlacesApi (com.google.maps.PlacesApi) to find all cafes within a 1000 m radius from a particular location. My problem is that cafes outside the given radius are being returned too. How can I find only the cafes within the radius?
Note: I want to implement this in a Java program instead of JavaScript(+HTML).
This is my textSearchQuery call:
PlacesSearchResponse response = PlacesApi.textSearchQuery(context, "cafe")
.location(currentPoint)//where currentPoint = new LatLng(13.039083, 77.610890)
.radius(1000)//1 KM
.await()
Use a Places Search (example) instead of a textSearchQuery.
From the docs, Text search won't filter results outside of given bounds:
You may bias results to a specified circle by passing a location and a radius parameter. This will instruct the Places service to prefer showing results within that circle. Results outside the defined area may still be displayed.

Estimating the radius of a location using google maps

I am using google maps API to get coordinates from a typed location. What I was also hoping to do was get the radius of the place, possibly using "bounds".
For example, if I geocode "England" it gives me a coordinate, but it doesnt tell me it's radius is very large. Whereas if I geocode "London" it again gives me a coordinate but doesnt tell me that it's radius is much smaller.
So my question is, is it possible to get an estimate of the size of the area being geocoded from the google API as well as it's center coordinate point?
Thanks!
You should be able to get the bounds via the GeocoderResult's geometry.bounds or geometry.viewport properties.
https://developers.google.com/maps/documentation/javascript/reference#GeocoderGeometry

Google maps search by address component

I have implemented a basic google places autocomplete in my web app, for example saying "Heraclion, Crete" and it translates it to the latlng coordinates that I want. I also used the mysql radius example from the api to show nearest entries. I also have locations in a second area of Crete, called "Rethymnon".
The problem now is the following. Supposedly one types just Crete. How can I get all the entries from Heraclion and Rethymnon? My code uses the radius approach as mentioned before. So I need something else to define it in a rectangular area.
Is this possible?
If the result contains a viewport (LatLngBounds), you could use that.
PlaceResult
geometry: The Place's geometry-related information. This includes:
location provides the latitude and longitude of the Place.
viewport defines the preferred viewport on the map when viewing this Place