I am using following API to get all places from current location,
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
#Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
Log.v("App",
"2. likelyPlaces.getCount() : "
+ likelyPlaces.getCount() + ", placeType : "
+ placeType);
places.clear();
GooglePlace place;
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
place = new GooglePlace();
place.setAddress(placeLikelihood.getPlace()
.getAddress());
place.setId(placeLikelihood.getPlace().getId());
place.setLatLng(placeLikelihood.getPlace()
.getLatLng());
place.setName(placeLikelihood.getPlace().getName());
place.setPhoneNumber(placeLikelihood.getPlace()
.getPhoneNumber());
place.setPriceLevel(placeLikelihood.getPlace()
.getPriceLevel());
place.setRating(placeLikelihood.getPlace()
.getRating());
places.add(place);
}
mAdapter.notifyDataSetChanged();
likelyPlaces.release();
}
});
This one returns only 20 places, and also no photo of the place. So I want to know how to get all places around 2 kilometers from current location. Also how to get the place image.
I know we can get more than 20 results by using
https://maps.googleapis.com/maps/api/place/search/xml?location=Enter Latitude,Enter Longitude&radius=10000&types=store&hasNextPage=true&nextPage()=true&sensor=false&key=enter google_map_key &pagetoken="Enter the first page token Value"
But for this API we have to provide Server IP for get API key. So need to know how can we get more than 20 results by using
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
Any help will be highly appreciable.
Don't know if you found answer already but you should check this out if not:
The Places API will return up to 20 establishments per query; however, each search can return as many as 60 results, split across three pages
https://stackoverflow.com/a/9627664/3677394
Related
Is it possible to get user's current Lat Long using Places API, instead of Maps API? I'm sure there's a process that involves user's current Lat Long but is it possible to get them?
Currently I'm creating activities that use Places API, and now I need user's current Lat Long, I think it's not worth to add Maps API only for that function.
If your requirement is to fetch only the Lat Long of the current location, then you don't need to use any Api. You may follow the below tutorial to implement it without using Place Api
https://www.androidhive.info/2015/02/android-location-api-using-google-play-services/
If you still want to use Place Api then you need to use Places.PlacesDetectionApi.getCurrentPlace method to create a PendingIntent that returns with a PlaceLikelihoodBuffer. First define the GoogleApiClient and use the below code to fetch the location -
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace( mGoogleApiClient, null );
result.setResultCallback( new ResultCallback<PlaceLikelihoodBuffer>() {
#Override
public void onResult( PlaceLikelihoodBuffer likelyPlaces ) {
PlaceLikelihood placeLikelihood = likelyPlaces.get( 0 );
String content = "";
if( placeLikelihood != null && placeLikelihood.getPlace() != null && !TextUtils.isEmpty( placeLikelihood.getPlace().getName() ) )
content = "Most likely place: " + placeLikelihood.getPlace().getLatLng()+ "\n";
if( placeLikelihood != null )
content += "Percent change of being there: " + (int) ( placeLikelihood.getLikelihood() * 100 ) + "%";
mTextView.setText( content );
likelyPlaces.release();
}
});
For more info, refer to this article - https://code.tutsplus.com/articles/google-play-services-using-the-places-api--cms-23715
I've been trying for the last few days to get Sleep information from the google fit API.
I've managed to get data from the history API and the session API for the time period, but the activity list doesn't seem to include any sleep data.
I've been capturing the data in "Sleep as Android" and I've also tried "Instant". But don't see anything in the data sets coming back.
I seem to remember with the older fit app I'd see the sleep activity shown, but there's no sign of the data in the journal section of the new app.
Should I be able to get the data from the history or session data?
At the moment I'm using
DataReadRequest readRequest = new DataReadRequest.Builder()
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.read(DataType.TYPE_ACTIVITY_SEGMENT)
.build();
Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(context))
.readData(readRequest)
.addOnSuccessListener(new OnSuccessListener<DataReadResponse>(){
#Override
public void onSuccess(DataReadResponse dataReadResponse) {
List<DataSet> dataSets = dataReadResponse.getDataSets();
for (DataSet dataSet : dataSets) {
for (DataPoint dp : dataSet.getDataPoints()) {
for (Field field : dp.getDataType().getFields()){
LogUtil.d("google fit Start: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " End: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " type: " + showDataType(dp.getValue(field)));
}
}
}
}
}
I'm not sure what I'm missing to get at the correct data. I see walking, still, running etc, but just no sleep!
You can try to send a session request that will read the dataType.TYPE_ACTIVITY_SEGMENT or used the Users.sessions methods to correctly record fitness data the sleep activities.
List of activities:
Sleeping 72
Light sleep 109
Deep sleep 110
REM sleep 111
Here is the sample code from Martin Stava that will show you on how to use Sleep as Anroid data from Google Fit. Hope it helps.
I am creating an Android App , an Uber Clone. In this I am using Firebase to list the rides created by the user.
The Ride stored in the following format .
{
"category" : "NUVO",
"driverids" : "",
"drop_lat" : "40.7127753",
"drop_long" : "-74.0059728",
"estdate" : "Wed#Feb#28th",
"estmile" : "4.19",
"esttime" : "01:02#PM",
"esttotalfare" : "4.61",
"fareest" : "1.1",
"g" : "t9z83wv46x",
"l" : [ 40.674426, -73.944033 ],
"notes" : "Gv",
"orgin_lat" : "145 Brooklyn Ave, Brooklyn, NY 11213, USA%20New York, NY, USA",
"request_id" : "5a75579740d166e95b8b4567",
"requested_category" : "FAM_SUV",
"rider_id" : "5a507bf340d16660288b4567",
"status" : 1,
"trip_id" : 0
}
Now I am Using GeoFire's GeoQuery's queryAtLocation to pick all rides with in 5 KMs from his current location.
The query uses the lat & lang from the field "l" and compare it with the current location lat & lang of the driver.
If the list's lat & lang is within 5 KMs , it will return the key , that is the parent name of the child "l".
Now I am currently in India. I use Lockito App to fix a Mock GPS location in India. After that I create a Ride within 5 KMs radius.
Now , the ride successfully listed in the drivers list. No Problem.
My Issue
But When I fix a mock GPS location in USA , this flow not working. I fixed the driver location on Brookyln Childeren's Museum and also created a ride on the same museum. But GeoQuery not calling onKeyEntered . It simply exists after calling GeoQueryReady function .
I check my current Lat & Lang from the app and it returns as 40.67434763453142,-73.94402358680964. I checked this against the lat&lang on field "l" .(refer above JSON). Both pointing to same location.
But GeoQuery failed to retrieve it
My Question
Why this issue happening ?. If I use India's locations. Geoquery works perfectly .
But why it failing in USA.
You may tell ,"There will be an issue in lockito". But Lockito returning correct location lat lang . I checked it in Logcat. And , if there is a issue in Lockitto then How it working in India.
Here My GeoQoery Code :
try {
showDialog();
double nearByDistanceRadius = 5.00d;
com.firebase.geofire.GeoFire geoFire = new com.firebase.geofire.GeoFire(FirebaseDatabase.getInstance().getReference().child(childtype));
final com.firebase.geofire.GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latitude, longitude), nearByDistanceRadius);
geoQueryEventListener=new GeoQueryEventListener() {
#Override
public void onKeyEntered(final String key, GeoLocation location) {
Toast.makeText (getApplicationContext(), "The key is = ",Toast.LENGTH_LONG).show();
}
#Override
public void onKeyExited(final String key) {
System.out.println("ON KEYEXITED"+key);
}
#Override
public void onKeyMoved(String key, GeoLocation location) {
System.out.println("ON KEYMOVED"+key);
}
#Override
public void onGeoQueryReady() {
System.out.println("ON KEYQUERYREADY");
#Override
public void onGeoQueryError(DatabaseError error) {
System.out.println("ON KEYERROR"+error);
}
};
geoQuery.addGeoQueryEventListener(geoQueryEventListener);
} catch (Exception e) {
e.printStackTrace();
}
Above , except onGeoQueryReady , no method called if I use USA. But it's
working in India. Can anyone tell me why that is the case?
This maybe long gone n dusted but perhaps can help others.
Since u mention its mock GPS coordinates. and u probably manually entered them.
GeoFire uses a special g: "code" (10 digit code) which is area wise / city wise
if you use the same g code in the same city / country (India in ur case) it will work fine !
However,if you use the same code in another country , geoQuery will fail. To make it work. u need to add one line in your code
geoFire.SetLocation() and someone in USA needs to run that code once only. geoFire will save a special key in g: "" Location. After you have the key you can remove that line from your app.
You can use that key generated by geoFire to manually enter as many locations as you want in USA and geoQuery will always work on that !!! Make sure you use the same pattern as geoFire does.
g:
l:
0:
1:
It took a while but I figured. It's that buggy geofire dependency. Downgrade from 3.0.0 to 2.3.1 solved it.
I am using Google Fit API, be specific using HistoryApi
I am using Fitness.HistoryApi.readDailyTotal to get steps, calories and distance. From that I got steps and calories but distance is creating problem. But onResult is not getting called. Any help would be highly appreciated.
PendingResult<DailyTotalResult> distanceResult = Fitness.HistoryApi
.readDailyTotal(mClient, DataType.TYPE_DISTANCE_DELTA);
distanceResult.setResultCallback(new ResultCallback<DailyTotalResult>() {
#Override
public void onResult(DailyTotalResult dailyTotalResult) {
if (dailyTotalResult.getStatus().isSuccess()) {
DataSet totalSet = dailyTotalResult.getTotal();
long distance = totalSet.isEmpty()? 0: totalSet.getDataPoints().get(0).getValue(Field.FIELD_DISTANCE).asInt();
Log.i("-------------", "distance= " + distance);
}
}
});
From above code if (dailyTotalResult.getStatus().isSuccess()) { this is false in case of distance and it returns true while I try to get steps and calories.
All above code is run in background thread.
Can you please try adding below scope ?
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
Also upgrade with new fit api:
compile 'com.google.android.gms:play-services-fitness:10.0.0'
I am doing a location search from my android app. User enter an address and I do a lookup with the following code,
private void doSearch(String query){
FNMApplication.logInfo("Searching:"+query);
//create a geocoder
Geocoder gc = new Geocoder(this,Locale.getDefault());
try{
//lookup locations which match the query input by the user
List<Address> addresses = gc.getFromLocationName(query, 5, -44.00, 111.00, -12.0, 155.0);
//if there are any results save them in an ivar for re-use
locationSearchResults=addresses;
promptSearch();
}
catch (Exception e){
;
}
}
The bounding box above is for australia but if I search for "Los Angelos" it returns results in the US. Is there something I have missed? As I see it, it should only return addresses within the bounding box as per the reference document
From the Question I tried this and the results I got are shown below.
18.55, 72.54 = Mumbai
22.18, 70.56 = Rajkot
1)
When I pass lower latitude vaue as left lower and search for the string I got this
Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocationName("akshardham", 5,
18.55, 72.54, 22.18, 70.56);
Log.i("Address", "=========0----------------------"
+ addresses.get(0).getAddressLine(0)
+ addresses.get(0).getAddressLine(1));
Log.i("Address", "=========0----------------------"
+ addresses.get(1).getAddressLine(0)
+ addresses.get(1).getAddressLine(1));
Log.i("Address", "=========0----------------------"
+ addresses.get(2).getAddressLine(0));
Log.i("Address", "=========0----------------------"
+ addresses.get(3).getAddressLine(0));
Log.i("Address", "=========0----------------------"
+ addresses.get(4).getAddressLine(0));
} catch (Exception e) {
;
}
Logcat of this
11-17 12:42:32.419: INFO/Address(802): =========0----------------------AkshardhamNH 8C, Sector 20
11-17 12:42:32.429: INFO/Address(802): =========0----------------------AkshardhamRajkot, Gujarat 360005
11-17 12:42:32.429: INFO/Address(802): =========0----------------------Akshardham
2)
When I pass higher latitude vaue as left lower and search for the string I got this
List<Address> addresses = gc.getFromLocationName("akshardham",5, 22.18, 70.56,18.55, 72.54 );
Logcat of this
11-17 12:43:53.170: INFO/Address(837): =========0----------------------HardhamPulborough, West Sussex RH20 1
3)
The doc here itself says "The addresses matching inside the bounding box is given higher rank." , I think they mean to say, Its not necessary that If search string is address between this box only will be return,if they found the address they will return even if its out of bounding box.
I Suppose;Bounding Box is just for setting the priority of result while getting means result from the box wil be first and and then other like in get(0),get(1) of the list. but the result will be given even if they are not in bounding box.
4)
In the Geocoder.java here they are just calling the method to get addresses with passing double values as argument simple..no any checking for the result is used there else to check the lowest and highest value
=> So final answer to you problem you just call the function as you are calling and you can check the second address line that does they matches to yours means the state or country is same. to find the country,state name of your bounding box value use getFromLocation(latitude, longitude, maxResults), I still Didn't Find A Perfect Solution For this,So me too Searching
=> More on this can be explained by an expert (That's I am not) or Developer from Google itself.