I am working on an app where I need to check if some points are within a city or X km outside of it, so I need to find the city's radius then add the X variable to it. I've been looking on Google Maps and OpenStreetMap and I could not find such info.
Is there any API that provides the city's average width? Or distance between the center and the edge?
Based on the Latitude & Longitude of two given points, you can find the distance between those points.
So fetch the Location (Latitude & Longitude) for the centre of city and the point needed, using Google Maps API's and find out the distance implementing the logic.
Logic is described in below link :
http://www.movable-type.co.uk/scripts/latlong.html
Post calculation of distance, you verify if it is in the required range based on X.
I came across the same problem and here is the best method I found so far,
Using the service Geoapify
you can find the placeid for a city using the geocoding API
We can then create a location filter based on the place id as documented here
we can also use that filter for autocomplete to allow only for places inside the city
Related
Is there a way by using azure-maps or google-maps to get from longitude and latitude all postal codes and municipalityes that are in range of X kilometers?
I've yet checked the Get Search Nearby of azure, but it returns only points of interests and it is not possible to specify in the API a range in which the data should be get.
In Azure Maps, getting all postal code/municipalities within a specified distance of a location or within an area is not currently available. However, this is something being investigated as a possible future service. Consider submitting this as a feature request here: https://feedback.azure.com/forums/909172-azure-maps
I don't believe Google Maps has any such service either.
I am building a site that helps people to find restaurants on the net .. so i want for every restaurant to show a small Google Map
Now i'm still building my database, in the table restaurant i have id ,name , phone, website, ....
My question is do i have to add other properities to help me locate the place exactly on Google Maps, what are they?
Please note that this is my first time to work with google maps, and i really dont know what do i need exactly to know about a place to represent it on the map.
Thanks
There are several ways to locate a place. First, you can do it through latitude and longitude. For this you can use Reverse geocoding which can translate the latitude & longitude into an address. You also have the option of using place_id, it is used to uniquely identify a place in Google Maps. See Places IDs. You also have the option of using the address of the place but I do not recommend it; due to the fact that there can be multiple places with the same name.
As for the properties that is available for the place, you may want to look at Place Details of Places API. This will return details like latitude,longitude, place_id, international_phone_number, opening_hours, permanently_closed, price_level, reviews etc.
Hope this will help you. Good luck!
To locate a place in google map, we need latitude and longitude.
for eg. in android ,to mark a location
static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker perth = mMap.addMarker(new MarkerOptions()
.position(PERTH));
here -31.90 and 115.86 are that places latitude and longitude respectively.
I think the logic may b same in all platforms
I'm using the google maps api for geocoding addresses. If I geocode a plain location name (e.g. Munich) the api returns corresponding latitude and longitude.
To which position do these coordinates refer to? Is it the (geographical) center of the location or the position of the administrative headquarter or what else?
They refer to the equator which is latitude=0° and the prime meridian which is longitude=0°. This represents the central point (starting point).
You can look at it as to the Cartesian coordinate system starting from (0,0)=(x,y) and retrieving all the other places by changing the x(long) and y(lat) coordinates. So yes, the answer is geographical centre.
EDIT:
url (video): https://www.youtube.com/watch?v=Spel7vfkpNc starting at 2:43
Basically, companies within the country decide on which lat, long will a city, country when searched appear. For example if you are searching for London the pin point will be assigned to particular coordinates depending on the company decision.
I've got a problem with Google Autocomplete rest api.
I need to return predictions only for certain radius, but "radius" parameter doesn't filter incorrect results. Currently I get results from another cities and even other countries.
How can i force google autocomplete to not include any results that out of requested radius?
The location and radius parameters only act as a bias to the results, there is currently no way to restrict results to a specific radius. You can however restrict results to a specific country by passing the components parameter as detailed in the documentation.
If you use the location, radius and component parameters you will most likely get the desired results.
An example search for Eiffel Tower, with a lat,lng location in Melbourne, Australia, radius 50km, and country restrict to Australia returns "Eiffel Tower Chocolate & Confectionery" as the real Eiffel tower is not within the radius or in the country that the request is restricted to:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Eiffel+Tower&location=-37.816836,144.963123&radius=50000&components=country:au&sensor=false&key=your_api_key
You can use optional parameter radius.
radius — The distance (in meters) within which to return Place
results. Note that setting a radius biases results to the indicated
area, but may not fully restrict results to the specified area. See
Location Biasing.
The only way I can see to force this is to do the filtering yourself in the result array that you get when performing the search. I haven't used the Autocomplete API, but it seems you are using the Maps API to search? In that case, you get a GeocoderResult object which you can inspect the coordinates for the items, and compare them to your desired point and radius.
A bit hacky, but quite straightforward.
This example (uses the Google Maps API v3 places library):
http://www.geocodezip.com/v3_GoogleEx_place-search.html
from this answer:
Google places autocomplete - location and radius not working
uses rankby=distance
You can process the results to remove any not within your desired radius.
I want to calculate the driving distance between two locations [the user's specified locations], before user starts the driving. I used many formulas and getDistanceFrom in CLLocation also, but I am not able to get the perfect the driving distance between those locations.
There is much difference in actual and calculated distance.
Please help me to calculate the driving distance between two locations.
How can I use Google Maps API to calculate the driving distance ?
I have already use the regexkitlite to show the road path on Google Maps between the two place. However I can't calculated the path distance.
If you have any code/link, please send it to me.
Thanks in advance....
See directions API of Google Maps
You have just to make a HTTP request:
http://maps.googleapis.com/maps/api/directions/output?parameters
Answer could be json or xml. You will find the distance in the answer
If you have two LatLongs you can calculate the direct distance between them; however, since you want driving directions (not as the crow flies) you'll need access to street-center-lines, so you can calculate the distance for each "leg" of the trip.
Google Maps may provide driving directions along with route distance, you'll need to check the documentation for that specific functionality.
edit
On a second look, it appears this may not be available on the API (as of 2006), but a work-around is posted here: http://groups.google.com/group/Google-Maps-API/msg/4dc2fad4f74e3314
Using Core Location API it will only give you the distance between two point in a straight line - most roads aren't, and hence the distance will be wrong.