I want to show food stores as per user street for example if user is in street name called ABC then map will show only those marker which is around in street ABC
if (userlocation == "isInStreet1") {
thencallThisfunction();
}
else if (userlocation == "isInStreet2") {
Toast.makeText(getActivity(), "There is no food store around you", }
but i don't have any idea how to do this ... i can able to get current location of the user but i am not getting how to show nearby object as per their location
Have you considered using the GPS to get your coordinates and then using them to get the address info including the street name. Once you have that infomration you can compare the strings to the list of street names you have.
See the accepted solution from this question: Android - How to get street name from coordinates?
It seems like you'd want to use the Google Places API.
In particular the Places 'search' function which allows you to find places near a specified Latitude/Longitude
Related
I have an requirement, in which Marker should be placed on clicking the Map within the city limit in Google Maps android.If user clicks on the map outside the city limit. Need to show an warning. I know it is possible to add marker on clicking on the map but how can i restrict it to city limit? I tried exploring the concept of GeoJson to add an layer above my Map.But I am not sure how this would help. Any suggestion appreciated. Thanks
Based on this link I could able to fetch polygons for a particular city. The values are stored to DB and fetched using an API. API returns lat lng boundary of a city, Using this I could able to draw an polygon in shape of City.
val polygon = googleMaps?.addPolygon(PolygonOptions()
.addAll(cityLimit)) // cityLimit LatLng list of City Boundary
polygon?.isClickable = false
polygon?.strokeWidth = 2f
Then onMapClick, I added the following condition
override fun onMapClick(latLng: LatLng?) {
if (!PolyUtil.containsLocation(latLng, cityLimit, false))
// Show error message "Unable to place marker outside city limit"
}
PolyUtil is an Class library of Google Maps sdk. This solved my problem. For more details check this blog
You should create a Geofence around the area you want the user to select. Then you can evaluate whether it is in the city boundaries.
Have a geofence like 10000m around the city,if the user clicks the map and find that it is not inside the geofence you cancel the request but if it is within the boundaries you create a marker
I am using AutoComplete Place google API, but i am getting results outside my country or state. But i need results near to my current location.
Say I am in India, Chennai, if I type 'C' in AutoCompleteEditText, I ll get Central Park, New York, USA as my first result. But I need Chennai as in google map.
Please check the below img links for ur reference...
What i need is this...
But I am getting this..
I wanted to make an android app which provides the distance between two areas in a city.
The user will have two input fields where he must enter the two area names he would like to find the distance.
After he enters the area name. My app should display the distance.
How should I implement this?
First of all you need to find latitude and longitude of that area name.
Convert both address in Location object, refer this.
Calculate distance by using distanceTo()
location1.distanceTo(location2);
Returns the approximate distance in meters between this location and
the given location.
refer this for distanceTo() detail.
First get latitude and longitude of your start point and end point and using
distanceBetween method of Location class calculate the distance here is link
http://developer.android.com/reference/android/location/Location.html#distanceBetween(double,%20double,%20double,%20double,%20float[])
Use the Google Maps Directions API. You'll need to request the directions over HTTP. You can do this directly from Android, or via your own server.
For example, directions from Montreal to Toronto:
GET http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false
You'll end up with some JSON. In routes[].legs[].distance, you'll get an object like this:
"legs" : [
{
"distance" : {
"text" : "542 km",
"value" : 542389
},
You can also get the polyline information directly from the response object.
for more detail visit here. Get the distance between two locations in android?
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.
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?