Getting bounding-box of city - gis

I want to know how far a specific geographic coordinate is from a list of cities ('far' meaning the euclidean distance between the coordinate and the city, not taking roads into account). For this I need to find a bounding-box for each of the cities - all located in Israel.
This post discusses country bounding-boxes, but I need them at the city level.
Is there any way to get this information for a long list of cities, other than drawing rectangles by hand on a map and extracting the coordinates?

You can find the bounding box of those cities at www.mapdevelopers.com/geocode_bounding_box.php. Entering a city will display a box on a map and give the latitude and longitude of each side. Hopefully that will give you the information you need.

For a long list of cities, use the Google Geocoding service. Once you get set up, you can use any language to access the REST API. For example you could use the popular standard requests library for Python.
Or, you could use Google's own Google Maps Java API, Python API, or JavaScript API. Any of these contain the Google Geocoding service.
See some simple examples of the Python and Java library here: https://developers.google.com/maps/documentation/webservices/client-library.
Here's the schema for the Geocoding results:
results[]: {
types[]: string,
formatted_address: string,
address_components[]: {
short_name: string,
long_name: string,
postcode_localities[]: string,
types[]: string
},
partial_match: boolean,
place_id: string,
postcode_localities[]: string,
geometry: {
location: LatLng,
location_type: GeocoderLocationType
viewport: LatLngBounds,
bounds: LatLngBounds
}
}
The bounding box is located in the geometry>viewport variable and looks like this
"viewport" : {
"northeast" : {
"lat" : 37.4238253802915,
"lng" : -122.0829009197085
},
"southwest" : {
"lat" : 37.4211274197085,
"lng" : -122.0855988802915
}
}

You can find the bounding box of those cities at
http://boundingbox.klokantech.com/
Entering a city/country will display a box on a map and give the latitude and longitude of each side. But accuracy is higher then at http://www.mapdevelopers.com/geocode_bounding_box.php (thx to #Fred for his answer)

I think, you need not bounding boxes, but city boundaries. Because with bounding boxes your analysis will be very rough, and to get a bounding box you anyway firstly need a boundary.
If you have now just list of cities, you need to get spatial data, the boundaries of all your cities. To find this data you can try this links. I would suggest to check Open Street Maps. Then you can use any GIS software (for example, open-source Quantum GIS) and calculate there the euclidean distances between your point and the city boundaries.
Hope this helps.

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!

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

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.

Google Maps Mystery Unit -- ca?

I'm working on understanding user events in Google Maps. Here's my sample code:
var listener = google.maps.event.addListener(map, 'rightclick', function(e){
console.log(JSON.stringify(e, null, 4));
});
The console returns:
{
"latLng": {
"lat": 36.29330392714158,
"lng": -115.24877548232325
},
"pixel": {
"x": 581.5555419921875,
"y": 374.7916578363487
},
"ca": {
"x": 46.04531521257013,
"y": 100.26925500235961
}
}
So I understand Latitude and Longitude.
The Pixel coordinates seems to represent the display on my webpage (with html canvas like output) When I move the cursor to the upper left corner of the visible map element in my web page, and right click, the console shows nearly 0,0 . Lower right hand corner matches to the pixel height / width of my display. So I can deduce that the Pixel feedback represents the display on my webpage.
I don't understand the context for a 'ca'? In fact what is a 'ca'? Anybody know? Is that an abbreviation for something? I can see that the 'ca' value barely changes when I right click on different areas of the visible map. I have no clue where 'ca' 0,0 ends up. How would you use a 'ca' element, what is it for? Anybody have an official reference? Many thanks.
The ca is an undocumented property of the object created by the closure compiler.
It will (or at least can) change with every release of the API so should not be used.
Related questions:
Google.Maps.Event settings - Va versus Xa
Google Places coordinates changing keys
Google Map Api Uncaught TypeError: Cannot read property '0' of null
Google Maps API V3 - only showing a blank map when using the geocoder
-Google maps - Weird geometry.location attributes (G, K)
Google maps api: what are xa and pa in get bounds?
item.geometry.location.kb & item.geometry.location.jb returning undefined

As of 2015, is there a way to get the boundaries of an italian post code using Google Maps APIs?

I looked at many SO questions referring to a similar topic:
Google Maps API V3: How to get region border coordinates (polyline) data?
Google has started highlighting search areas in Pink color. Is this feature available in Google Maps API 3?
Add "Search Area" outline onto google maps result
Where do Google and Twitter source political boundaries of cities, regions and states?
And searched for online tools and tools within my country and too:
https://market.mashape.com/vanitysoft/boundaries-io/overview
https://market.mashape.com/vanitysoft/boundaries-io
http://mapit.openpolis.it/postcode/00188.html
But no one of them fits with the task I need to complete (and I tell you why right after explaining the task I have to do):
Basically all I want is, for each Italian post code (called CAP in Italy) (as of 2015, they are 8709 and I have them all stored in a database's table), find its area coordinates (therefore something like an array with the following structure (it can be a JSON, KML, XML, it doesn't matter as long as the coords are truthful and I can somehow parse them):
[
[ [lat, lng], [lat, lng], [lat, lng], ... ], // Polygon 1
/*
* This additional arrays may be here in the case
* where a CAP (Italian postal code) is made up of many areas,
* therefore each area is a polygon.
*
* For example here -> https://www.google.it/maps/place/84020+SA/#40.605482,15.1783416,10.32z/data=!4m2!3m1!1s0x13396999456508e7:0x1c09e123127ecbc0
*
*/
[ [lat, lng], [lat, lng], ... ], // Optional Polygon 2
...
[ [lat, lng], [lat, lng], ... ] // Optional Polygon n
];
So that I can draw them with a google.maps.Polygon or a custom overlay extending the google.maps.OverlayView class on a map. The coordinates of the areas I need are shown by Google here:
https://www.google.it/maps/place/20122+Milano/#45.4628212,9.1931976,13z/data=!4m2!3m1!1s0x4786c6af4dceb2f5:0x1c0678057ae1afc0
Or here:
https://www.google.it/maps/place/84020+SA/#40.605482,15.1783416,10.32z/data=!4m2!3m1!1s0x13396999456508e7:0x1c09e123127ecbc0
But I can't find a way to get them in my application and I didn't find such a guide on their site at https://developers.google.com/maps/documentation/. Also, in the SO questions I linked the answers say that Google doesn't provide this data, but, as of 2015, maybe they have changed something?
Now, why no one of the features I have found suits my needs:
They all address to United States' zip codes only;
The local Italian site I have found (mapit.openpolis.it) doesn't return the coords for the polygon area but just the a single pair of lat and lng which points to the center of the postal code and also doesn't return anything for some postal codes (CAPs).
What could I do? Is there a way to contact a responsible of the Google Maps API team and ask him what should I do in such a case? (And I am pretty serious so don't laugh at me...).
Thanks for the attention.
You can check out the postal boundaries from open street map.

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