I retrieve the lat & long for the event detail. And I want to send lat long to calendar using intent. I search it on google but didn't find any solution? Please help.
You could attain this using CalendarContract class. Adding location is possible using this class; CalendarContract.Events.EVENT_LOCATION
More info here Adding event with reminders to calendar with 'Intent.putExtra()' way of doing
Using the Google API with other languages, I have been able to pass the Latitude and Longitude as a string and the map link in the Calendar Event drops a pin in the correct position. I would imagine that that API has the same behavior for all languages.
Source: Latitude and Longitude of the White House
C# psuedo code
var latitude = "38.8976763";
var longitude = "-77.0365298";
new Event
{
// beginning parameters
...
// The comma is optional and replaceable with a single space
Location = $"{latitude}, {longitude}",
...
// final parameters
}
image from Event detail added by Google API:
Resulting Link when clicking map from the Calendar Event:
map
Related
I am currently using the Google Places API within my (Java) Android application to get the current device location and display it into an editText. Currently when I make the call to placesClient.findCurrentPlace(request), a list of the closest places and the likelihood of the device being there are returned, like so:
Place 'XXXXXXX' has likelihood: 0.600000
Place 'YYYYYYY' has likelihood: 0.0500000
Place 'ZZZZZZZ' has likelihood: 0.00000
Where the places are things like "Thames River" or "Telus Stadium". I can then get the address from each of these from the response. My question is, is there any way to get back the address of the phones current location, opposed to the address of the closest 'Place'?
I have done something similar with the Places Autocomplete so that it suggests addresses rather than places, which works very well. Getting the current place is done in a slightly different way though, and therefore I can't seem to make the same change.
The reason that I am attempting to do this using the Places API is because I have a start and end location AutoCompleteEditText which the user can type into. They can choose to have their current location shown in the Start Location AutoCompleteEditText, and I was hoping to show the address in the same format as it would be in if they had typed in the address and clicked it using the Places AutoComplete.
Here is the code currently being used to get the address of the closest place, which I would like to modify to get the address the phone is currently at.
List<Place.Field> placeFields = Collections.singletonList(Place.Field.ADDRESS);
FindCurrentPlaceRequest request = FindCurrentPlaceRequest.newInstance(placeFields);
...
Task<FindCurrentPlaceResponse> placeResponse = placesClient.findCurrentPlace(request);
placeResponse.addOnCompleteListener(new OnCompleteListener<FindCurrentPlaceResponse>() {
#Override
public void onComplete(#NonNull Task<FindCurrentPlaceResponse> task) {
if (task.isSuccessful()) {
FindCurrentPlaceResponse response = task.getResult();
for (PlaceLikelihood placeLikelihood : response.getPlaceLikelihoods()) {
Log.i(LOG_TAG, String.format("Place '%s' has likelihood: %f",
placeLikelihood.getPlace().getAddress(),
placeLikelihood.getLikelihood()));
}
} else {
Log.e(LOG_TAG, "Error finding current location");
}
}
});
Forget having to use the Google Places API for this - It's simple to do without having to interact with any API.
Simply get the current location using a FusedLocationProviderClient to return the last known latitude and longitude of the device (as seen here), and then use an instance of Geocoder to get addresses from that latitude and longitude using the getFromLocation method. This can then easily be converted into a string which matches what the Google Places API would have returned (as seen here).
How can I empty a trash of a calendar via Google services?
I'm calling google services in Java (com.google.api.services.calendar.Calendar) but I need to empty trash after I deleted events.
I think I have found the only way to solve this problem:
Create a temporary calendar
Move into this calendar all events that I have to delete
Delete the temporary calendar
Like this code:
Calendar entry = new Calendar();
entry.setSummary("MyTrashCalendar");
Calendar result = client.calendars().insert(entry).execute();
...
Event updatedEvent = client.events().move('currentCalendarId', "eventId", "destinationCalendarId").execute();
...
client.calendars().delete(calendar.getId()).execute();
I hope this helps
I have a lot of geo data stored online with latitude and longitude and I'd like to use the distanceTo method instead of my own haversine formula.
So I need to put each record into a Location field, but here's my question: it requires a "provider" string. Why? What will Android do with that information?
for (ArrayList<String> item : Places_Data) {
Location itemloc = new Location("provider");
itemloc.setLatitude(latIn);
itemloc.setLongitude(lonIn);
//do something with my new location
}
From the source code for Location, it doesn't use the string to do anything meaningful. It just uses it to describe the Location internally. If you do Location#toString(), it prints out the co-ordinates, the provider and other details (accuracy, etc). That's all it's used for, internal description.
You can make the provider anything, as seen in this answer: Creating Android Location Object
Use correctly the way
package android.location.LocationManager
Location location = new Location(LocationManager.GPS_PROVIDER);
Use NETWORK_PROVIDER o GPS_PROVIDER
https://developer.android.com/reference/android/location/LocationManager.html#GPS_PROVIDER
https://developer.android.com/reference/android/location/LocationManager.html#NETWORK_PROVIDER
What I am trying to do is get a list of all the events in the default calendar only? I don't want any other calendars' events included, i.e., holidays.
I am using the ".../feeds/username/default/full" and doing a query for all events from 1 month ago to forever. I have two events that I have created but I get a feed with 25 entries. My two events first and then 23 holidays. I really don't them to be included at all but if them MUST be there, how do I detect them. The only thing I can find is the eTag for my two events is different from the holiday ones. But I can't just say get all the events from the first Etag I encounter because the default calendar may not have any events so the first one would be holidays.
Any help would be appreciated.
This can be done with a few lines of code using the latest version of the Google Calendar API. All you need to do is pull the events for the primary calendar, as documented here:
http://code.google.com/apis/calendar/v3/using.html#retrieving_events
The code you need is:
Events events = service.events().list("primary").execute();
while (true) {
for (Event event : events.getItems()) {
System.out.println(event.getSummary());
}
String pageToken = events.getNextPageToken();
if (pageToken != null && !pageToken.isEmpty()) {
events = service.events().list("primary").setPageToken(pageToken).execute();
} else {
break;
}
}
I wonder what version of the Calendar API you are using? In v3 I am able to all my events without getting the holidays. I added some more code examples, since the Google documentation is incorrect for connecting to the Calendar V3 API though Oauth2 for Java.
Use the code listed in the other post to loop though the Calendar events after the Oauth is setup and the Calendar is initialized. You probably can, but do not need to declare the events API. I just call it from the Calendar service(3). Note the Calendar ID I have listed is "Primary."
Calendar service3 = new Calendar(transport, jsonFactory, accessProtectedResource);
com.google.api.services.calendar.model.Calendar calendar = service3.calendars().get("primary").execute();
com.google.api.services.calendar.model.Events events = service3.events().list("primary").execute();
I've installed the Google Maps Java 2 ME app on my Nokia N73 which supports the Location API (JSR 179), but does not have an in-built GPS sensor. The "My Location" features works correctly, and is able to pinpoint my position within the city.
When I tried to access the CellID, LAC and other related data, I got nulls. So how is Maps able to calculate my position? Is it because their app is signed with a certificate? (mine isn't)
What it does is measure the signal strength of WiFi, 3G and GSM Base Stations/Access Points in the area. Since all WiFi access points have a unique MAC address, and 3G and GSM Base Stations also have unique identifications, it now knows which base stations you are close to and approximately how close to them you are, based on the strength.
There are now a few ways to find the distance. If it knows where the Access Point/Base Station is, then it can triangulate your position, based on the signal strength. For this to work it needs to have access to at least 3 AP/BS. With GSM it can also use the Timer Advance, which is an estimation of how far away you are from the base station, with an accuracy of approximately 1km. With 3G it's even better.
Another approach (used by Google and others) is that all your signal strength data is sent to a server. If you have a GPS then your GPS info is also sent along. The server can then build a map of signal strengths to different AP/BS at different coordinates. Since you don't have a GPS it now compares the signal strengths you have passed along and tries to find the closest match in its database, and then finds the location at that closest point.
This is easy to do in J2ME using the APIs defined by JSR 179. There's a simple example here: JavaME Location API Example application with Source Code (that page is broken at the time of writing; here's the Google Cache version).
That sample works perfectly on my Nokia E63, which like your N97 N73 doesn't have a GPS but does support cell-based positioning. Here's the core of it:
public void checkLocation() throws Exception
{
String string;
Location l;
LocationProvider lp;
Coordinates c;
// Set criteria for selecting a location provider:
// accurate to 500 meters horizontally
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(500);
// Get an instance of the provider
lp = LocationProvider.getInstance(cr);
// Request the location, setting a one-minute timeout
l = lp.getLocation(60);
c = l.getQualifiedCoordinates();
if(c != null ) {
// Use coordinate information
double lat = c.getLatitude();
double lon = c.getLongitude();
string = "\nLatitude : " + lat + "\nLongitude : " + lon;
} else {
string ="Location API failed";
}
midlet.displayString(string);
}
#Marius is right about how the technology works, but the JSR 179 APIs hide all that detail from you. #JaanusSiim is wrong that you can't do this from J2ME.
Note that the sample application doesn't require signing to work - the phone will pop up a prompt asking whether to allow the unsigned application to access your location information.