Locations: get
Stay organized with collections
Save and categorize content based on your preferences.
Requires authorization
Gets a single location by ID.
See an example.
Request
HTTP request
GET https://www.googleapis.com/mirror/v1/locations/id
Parameters
Parameter name |
Value |
Description |
Path parameters |
id |
string |
The ID of the location or latest for the last known location.
|
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope |
https://www.googleapis.com/auth/glass.timeline |
https://www.googleapis.com/auth/glass.location |
Request body
Do not supply a request body with this method.
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library.
import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Location;
import java.io.IOException;
public class MyClass {
// ...
/**
* Print information about the latest known location for the current user.
*
* @param service Authorized Mirror service.
*/
public static void printLatestLocation(Mirror service) {
try {
Location location = service.locations().get("latest").execute();
System.out.println("Location recorded on: " + location.getTimestamp());
System.out.println(" > Lat: " + location.getLatitude());
System.out.println(" > Long: " + location.getLongitude());
System.out.println(" > Accuracy: " + location.getAccuracy() + " meters");
} catch (IOException e) {
System.err.println("An error occurred: " + e);
}
}
// ...
}
.NET
Uses the .NET client library.
using System;
using Google.Apis.Mirror.v1;
using Google.Apis.Mirror.v1.Data;
public class MyClass {
// ...
/// <summary>
/// Print information about the latest known location for the current user.
/// </summary>
/// <param name='service'>
/// Authorized Mirror service.
/// </param>
public static void PrintLatestLocation(MirrorService service) {
try {
Location location = service.Locations.Get("latest").Fetch();
Console.WriteLine("Location recorded on: " + location.Timestamp);
Console.WriteLine(" > Lat: " + location.Latitude);
Console.WriteLine(" > Long: " + location.Longitude);
Console.WriteLine(" > Accuracy: " + location.Accuracy + " meters");
} catch (Exception e) {
Console.WriteLine("An error occurred: " + e.Message);
}
}
// ...
}
PHP
Uses the PHP client library.
/**
* Print information about the latest known location for the current user.
*
* @param Google_MirrorService $service Authorized Mirror service.
*/
function printLatestLocation($service) {
try {
$location = $service->locations->get('latest');
print 'Location recorded on: ' . $location->getTimestamp() . "\n";
print ' > Lat: ' . $location->getLatitude() . "\n";
print ' > Long: ' . $location->getLongitude() . "\n";
print ' > Accuracy: ' . $location->getAccuracy() . " meters\n";
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
}
Python
Uses the Python client library.
from apiclient import errors
# ...
def print_latest_location(service):
"""Print information about the latest known location for the current user.
Args:
service: Authorized Mirror service.
"""
try:
location = service.locations().get(id='latest').execute()
print 'Location recorded on: %s' % location.get('timestamp')
print ' > Lat: %s' % location.get('latitude')
print ' > Long: %s' % location.get('longitude')
print ' > Accuracy: %s meters' % location.get('accuracy')
except errors.HttpError, e:
print 'An error occurred: %s' % e
Ruby
Uses the Ruby client library.
##
# Print information about the latest known location for the current user.
#
# @param [Google::APIClient] client
# Authorized client instance.
# @return nil
def print_latest_location(client)
mirror = client.discovered_api('mirror', 'v1')
result = client.execute(
:api_method => mirror.locations.get,
:parameters => { 'id' => 'latest' })
if result.success?
location = result.data
puts "Location recorded on: #{location.timestamp}"
puts " > Lat: #{location.latitude}"
puts " > Long: #{location.longitude}"
puts " > Accuracy: #{location.accuracy} meters"
else
puts "An error occurred: #{result.data['error']['message']}"
end
end
Go
Uses the Go client library.
import (
"code.google.com/p/google-api-go-client/mirror/v1"
"fmt"
)
// PrintLatestLocation prints information about the latest known location for
// the current user.
func PrintLatestLocation(g *mirror.Service) error {
l, err := g.Locations.Get("latest").Do()
if err != nil {
fmt.Printf("An error occurred: %v\n", err)
return err
}
fmt.Printf("Location recorded on: %s\n", l.Timestamp)
fmt.Printf(" > Lat: %s\n", s.Latitude)
fmt.Printf(" > Long: %s\n", s.Longitude)
fmt.Printf(" > Accuracy: %s meters\n", s.Accuracy)
return nil
}
Raw HTTP
Does not use a client library.
GET /mirror/v1/locations/latest HTTP/1.1
Authorization: Bearer auth token
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eRetrieves a single location data point for a user by its ID, including latitude, longitude, timestamp, and accuracy.\u003c/p\u003e\n"],["\u003cp\u003eRequires authorization with either \u003ccode\u003eglass.timeline\u003c/code\u003e or \u003ccode\u003eglass.location\u003c/code\u003e scope.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003elatest\u003c/code\u003e ID can be used to retrieve the most recent location recorded.\u003c/p\u003e\n"],["\u003cp\u003eSample code snippets demonstrate this functionality in Java, .NET, PHP, Python, Ruby, and Go.\u003c/p\u003e\n"]]],[],null,["# Locations: get\n\n**Requires [authorization](#auth)**\n\nGets a single location by ID.\n[See an example](#examples).\n\nRequest\n-------\n\n### HTTP request\n\n```\nGET https://www.googleapis.com/mirror/v1/locations/id\n```\n\n### Parameters\n\n| Parameter name | Value | Description |\n|----------------|----------|-----------------------------------------------------------------|\n| **Path parameters** |||\n| `id` | `string` | The ID of the location or `latest` for the last known location. |\n\n### Authorization\n\nThis request requires authorization with at least one of the following scopes ([read more about authentication and authorization](/glass/authorization)).\n\n| Scope |\n|--------------------------------------------------|\n| `https://www.googleapis.com/auth/glass.timeline` |\n| `https://www.googleapis.com/auth/glass.location` |\n\n### Request body\n\nDo not supply a request body with this method.\n\nResponse\n--------\n\nIf successful, this method returns a [Locations resource](/glass/v1/reference/locations#resource) in the response body.\n\nExamples\n--------\n\n**Note:** The code examples available for this method do not represent all supported programming languages (see the [client libraries page](/glass/tools-downloads/client-libraries) for a list of supported languages). \n\n### Java\n\nUses the [Java client library](/glass/tools-downloads/client-libraries). \n\n```java\nimport com.google.api.services.mirror.Mirror;\nimport com.google.api.services.mirror.model.Location;\n\nimport java.io.IOException;\n\npublic class MyClass {\n // ...\n\n /**\n * Print information about the latest known location for the current user.\n *\n * @param service Authorized Mirror service.\n */\n public static void printLatestLocation(Mirror service) {\n try {\n Location location = service.locations().get(\"latest\").execute();\n\n System.out.println(\"Location recorded on: \" + location.getTimestamp());\n System.out.println(\" \u003e Lat: \" + location.getLatitude());\n System.out.println(\" \u003e Long: \" + location.getLongitude());\n System.out.println(\" \u003e Accuracy: \" + location.getAccuracy() + \" meters\");\n } catch (IOException e) {\n System.err.println(\"An error occurred: \" + e);\n }\n }\n\n // ...\n}\n```\n\n### .NET\n\nUses the [.NET client library](/glass/tools-downloads/client-libraries). \n\n```css+lasso\nusing System;\n\nusing Google.Apis.Mirror.v1;\nusing Google.Apis.Mirror.v1.Data;\n\npublic class MyClass {\n // ...\n\n /// \u003csummary\u003e\n /// Print information about the latest known location for the current user.\n /// \u003c/summary\u003e\n /// \u003cparam name='service'\u003e\n /// Authorized Mirror service.\n /// \u003c/param\u003e\n public static void PrintLatestLocation(MirrorService service) {\n try {\n Location location = service.Locations.Get(\"latest\").Fetch();\n\n Console.WriteLine(\"Location recorded on: \" + location.Timestamp);\n Console.WriteLine(\" \u003e Lat: \" + location.Latitude);\n Console.WriteLine(\" \u003e Long: \" + location.Longitude);\n Console.WriteLine(\" \u003e Accuracy: \" + location.Accuracy + \" meters\");\n } catch (Exception e) {\n Console.WriteLine(\"An error occurred: \" + e.Message);\n }\n }\n\n // ...\n}\n```\n\n### PHP\n\nUses the [PHP client library](/glass/tools-downloads/client-libraries). \n\n```php\n/**\n * Print information about the latest known location for the current user.\n *\n * @param Google_MirrorService $service Authorized Mirror service.\n */\nfunction printLatestLocation($service) {\n try {\n $location = $service-\u003elocations-\u003eget('latest');\n\n print 'Location recorded on: ' . $location-\u003egetTimestamp() . \"\\n\";\n print ' \u003e Lat: ' . $location-\u003egetLatitude() . \"\\n\";\n print ' \u003e Long: ' . $location-\u003egetLongitude() . \"\\n\";\n print ' \u003e Accuracy: ' . $location-\u003egetAccuracy() . \" meters\\n\";\n\n } catch (Exception $e) {\n print 'An error occurred: ' . $e-\u003egetMessage();\n }\n}\n```\n\n### Python\n\nUses the [Python client library](/glass/tools-downloads/client-libraries). \n\n```python\nfrom apiclient import errors\n# ...\n\ndef print_latest_location(service):\n \"\"\"Print information about the latest known location for the current user.\n\n Args:\n service: Authorized Mirror service.\n \"\"\"\n try:\n location = service.locations().get(id='latest').execute()\n\n print 'Location recorded on: %s' % location.get('timestamp')\n print ' \u003e Lat: %s' % location.get('latitude')\n print ' \u003e Long: %s' % location.get('longitude')\n print ' \u003e Accuracy: %s meters' % location.get('accuracy')\n except errors.HttpError, e:\n print 'An error occurred: %s' % e\n```\n\n### Ruby\n\nUses the [Ruby client library](/glass/tools-downloads/client-libraries). \n\n```ruby\n##\n# Print information about the latest known location for the current user.\n#\n# @param [Google::APIClient] client\n# Authorized client instance.\n# @return nil\ndef print_latest_location(client)\n mirror = client.discovered_api('mirror', 'v1')\n result = client.execute(\n :api_method =\u003e mirror.locations.get,\n :parameters =\u003e { 'id' =\u003e 'latest' })\n if result.success?\n location = result.data\n puts \"Location recorded on: #{location.timestamp}\"\n puts \" \u003e Lat: #{location.latitude}\"\n puts \" \u003e Long: #{location.longitude}\"\n puts \" \u003e Accuracy: #{location.accuracy} meters\"\n else\n puts \"An error occurred: #{result.data['error']['message']}\"\n end\nend\n```\n\n### Go\n\nUses the [Go client library](/glass/tools-downloads/client-libraries). \n\n```go\nimport (\n \"code.google.com/p/google-api-go-client/mirror/v1\"\n \"fmt\"\n)\n\n// PrintLatestLocation prints information about the latest known location for\n// the current user.\nfunc PrintLatestLocation(g *mirror.Service) error {\n l, err := g.Locations.Get(\"latest\").Do()\n if err != nil {\n fmt.Printf(\"An error occurred: %v\\n\", err)\n return err\n }\n fmt.Printf(\"Location recorded on: %s\\n\", l.Timestamp)\n fmt.Printf(\" \u003e Lat: %s\\n\", s.Latitude)\n fmt.Printf(\" \u003e Long: %s\\n\", s.Longitude)\n fmt.Printf(\" \u003e Accuracy: %s meters\\n\", s.Accuracy)\n return nil\n}\n```\n\n### Raw HTTP\n\nDoes not use a client library. \n\n```http\nGET /mirror/v1/locations/latest HTTP/1.1\nAuthorization: Bearer auth token\n```"]]