Hello I want to search nearest location using google place api....
from https://developers.google.com/places/documentation/supported_types i have used types in my code for searching nearest places....
and the code is below
try {
double radius = 5000; // 10000 meters
// get nearest places
nearPlaces = googlePlaces
.search(gps.getLatitude(), gps.getLongitude(), radius,
"sublocality|sublocality_level_4|sublocality_level_5|sublocality_level_3|sublocality_level_2|sublocality_level_1|neighborhood|locality|sublocality");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
but could not find nearest places
like if i am in "San Diego, CA, USA" then i want to get result like
Gaslamp/Downtown,
Pacific Beach,
Ocean Beach,
Uptown,
Hillcrest,
Mission Valley,
Fashion Valley,
North Park,
but instead of this i am getting only two value like
Mission Valley East,
Serra Mesa
so can any one help me what type i have to pass so i can get result like above instead of below result
My previous answer was deleted by a moderator for unknown reasons, I am re-posting with some more context as it is the currently the correct answer:
It appears you are trying return nearby geographical locations (anything from the second list in the supported place types). Unfortunately the Places API is not designed for this, it is designed to return a list of nearby establishments (anything from the first list in the supported place types) and up to two locality or political type results to to help identify the area you are performing a Place Search request for.
This is stated in the documentation here:
https://developers.google.com/places/documentation/search#PlaceSearchResponses
"results" contains an array of Places, with information about each. See Place Search Results for information about these results. The Places API returns up to 20 establishment results per query. Additionally, political results may be returned which serve to identify the area of the request.
If you type filter your Place Search request by a geographic location type like locality or political, you will filter out the establishment results and only be left with the area identity results.
A Places API - Feature Request for returning nearby localities has been filed here:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4434
If you believe this would be a useful feature please make sure your star the request to let us know you are interested in seeing it added.
double radius = 5000 is 5 Kilometers just over 3 miles.
If you increase the radius you should return more places
You should consider the distance to maximum 50Km and there are different types as follows:
establishment,lodging,spa,bar,church,place_of_worship etc.
Related
Google Static Maps API Documentation states:
Latitudes and longitudes are defined using numerals within a comma-separated text string that have a precision to 6 decimal places. For example, "40.714728,-73.998672" is a valid geocode value. Precision beyond the 6 decimal places is ignored.
However, I have noted that in many cases, that precision is not enough.
(Edit: Actually, 6 decimal places allows a precision of approximately 2 cms, as 323go comments. See the edit at the bottom for further info)
E.g: Trying to put a marker on the Eiffel Tower (Lat: 48.8583701,Lon: 2.2922926) gets truncated (to Lat: 48.858370, Lon:2.292292) obtaining the following result, which has a non negligible offset:
I use static maps is because in my application I show multiple maps simultaneously inside the items of a RecyclerView.
I currently achieve that by asynchronously injecting the images returned by the Google static maps API via Picasso.
This current approach works well and performs smoothly, the only problem being the lack of precision of the map.
As a workaround, I am considering using the standard MapView in Lite Mode, but I am concerned that it could lead to performance issues, as stated in this question
Is there a way to overcome that limit, even if it requires paying?
Edit
I was using wrong coordinates. I'll explain how I got them, just in case anyone else makes the same mistake.
I was using the coordinates that appear in the URL after loading https://google.com/maps/place/Tour+Eiffel, which in my case is this URL.
When the left side panel of the web version of Google Maps is open (which is the default behaviour), the pin appears to be in the center of the map.
Nevertheless, the coordinates of the URL represent the center of the map including the part under the left panel. This is easy to notice once the left panel is collapsed.
This is what caused the horizontal offset.
Im trying to figure this out but on my side everything is working fine and precise, i noticed you are using different coordinates than mine
For the Eiffel Tower i used:
48.858285, 2.294388
That should give you a better result, also remember you can place a marker with the name of the place or with the full address with Geocoder which is:
Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France
Something like this should help
Geocoder geocoder = new Geocoder(<your context>);
List<Address> addresses;
addresses = geocoder.getFromLocationName(<String address>, 1);
if(addresses.size() > 0) {
double latitude= addresses.get(0).getLatitude();
double longitude= addresses.get(0).getLongitude();
}
In Android's Geocoder, method getFromLocation can return more than one address for a given lat long. But lat long uniquely represents a location on earth surface, so why does it return multiple objects?
Reverse geocoding translates latitude, longitude into a human-readable address. However, there are different objects that you may be interested in. For example, you can search the nearest street address, the nearest postal code, the neighborhood, the city, etc. For this reason reverse geocoder returns more than one result.
Please look at this example in the Geocoder tool.
As you can see the first result has a type street_address, the second result has a type bus_station, the third has a type neighborhood, and so on until the country level.
Hope my answer addresses your doubts.
Because a lat long position might not have a proper name, or it might refer to different names altogether.
Let's say, it points to the exact center of a square of undeveloped land, surrounded by 4 streets.
Depending on a country's rules & regulations, the owner of the land might be forced to 'attach' that piece of land to one of the 4 streets... or the land might be 'address-less' (only defined by its boundaries). In the latter case, the land might be attached to all 4 streets, allowing future purchaser/developer to choose the most 'catchy' address.
Or, a building just got renamed. For awhile, people won't recognize the new name. It's just wiser for reverse geocoding to return both the old name and the new name.
Another possibility is for the reverse geocoding to return "defined" names within X meters around the lat long position.
I have an question that while using Google Direction Api we can get the list of data like city's name, its Lat & Lng etc but the data provided by Api is limited to some extend. It's not able to provide all cities coming with-in that particular route.
E.g. If we try to go for Chandigarh to Delhi, then the route has a fixed result but when we try to reverse that same search i.e. Delhi to Chandigarh, some of the cities coming in previous result get vanished in api's new result, moreover, we just have a limited amount of locations/cities in result while we need the route completely detailed.
Do any of you guys faced this issue before? Is there any other way to match such requirement?
Hope I am understandable.
Thanks.
Use the below url:
https://maps.googleapis.com/maps/api/directions/json?origin="latvalue","longvalue"&destination="destnLat","destnLong"
&sensor=false&avoid=highways&mode=driving&alternatives=true
you have to set the alternatives value to true so it will result different routes available between the source and destination
i have developed an application that interacts with google places api to search for cafe in the neighborhood of a user. for the purpose of my application i want to have the radius set to a very small value.. may be 20 to 50 meters. currently my app is working but its not working the way it should.
In my app, i have set the radius to 350 meters. so practically it should return me the list of cafe that fall in the radius of 350m. however my app still shows starbucks in this result set even if starbucks is 650m (road distance) and 500m (straight distance). I would like to know what should be done to get the correct results.
Currently i am using GPS for this. will a combination of gps and network service provide me a better reading?
public PlacesList search(double latitude, double longitude, double radius, String types)
throws Exception {
this._latitude = latitude;
this._longitude = longitude;
this._radius = radius;
this question is not related to Android, but to the Google Places API.
are you using place search or text search? both of them have comments regarding location biasing
text search:
"You may bias results to a specified circle by passing a location and a radius parameter. This will instruct the Place service to prefer showing results within that circle; results outside of the defined area may still be displayed."
place search:
"distance. This option sorts results in ascending order by their distance from the specified location. Ranking results by distance will set a fixed search radius of 50km. One or more of keyword, name, or types is required."
I am getting a latitude and longitude from GPS and want to search the nearest city from my current location.
Currently I'm sending a request to Google Places with types like "neighborhood|locality", but this does not return any nearest city. Even if I only specify "neighborhood" or "locality" by themselves, I still get no results. However if I use a type like "bar" then it returns a list of bars.
I'm using the types listed here:
https://developers.google.com/places/documentation/supported_types
Can anybody tell me what Place Type I should use to get the nearest city or places, or how I can otherwise get the nearest city?
Are you getting back a results array with nothing in it, or simply getting nothing back? The docs say you'll get a results array "even if the service returns no results". Is it possible that the city you're searching contains bars but does not contain anything classified as a "neighborhood" or a "locality"?
This question says
you can restrict the results that will come back in the Autocomplete
to addresses by setting types to 'geocode' ... you can restrict the
results that come back in the Autocomplete to cities by setting types
to 'cities'
If you're just trying to get the city name, rather than searching for something inside the city, perhaps you want to use one of those options?