Location information is important for many applications that have addresses to search for. For example, for applications such as dianping, we can get some information about the current location through the address. In this article, we'll show you how to get location information in the scope schema. This location information can be very important for many of our searches.
1) Create a simple scope application
We first open the SDK and select the "Unity Scope" Template:
Next, we select "Empty scope". This allows us to create one of our most basic scopes.
We can run our scope. This is one of the most basic scopes.
2) Add code to get location information we set our code in order to obtain position information. First open the. ini file in the "Data" folder and add Locationdataneeded=true. This displays the entire file as:
[Scopeconfig] DisplayName = Scopetest Scopedescription = This is a scopetest Scopeart = Screenshot.pngauthor = Firstname Lastnameicon = Icon.pnglocationdataneeded=true[appearance]pageheader.logo = Logo.png
At the same time we open the Scope.cpp file and modify it to:
#include <unity/scopes/SearchMetadata.h>//added....void Query::run (sc::searchreplyproxy const& reply) {TR y {cerr << ' starting to get ' the location ' << Endl; Auto metadata = Search_metadata (); if (Metadata.has_location ()) {Cerr << "It has location data" << Endl; Auto location = Metadata.location (); if (Location.has_country_code ()) {cerr << "Country code:" << location.country_code () << Endl } if (Location.has_area_code ()) {cerr << "area code:" << location.area_code () &l t;< Endl; } if (Location.has_city ()) {Cerr << "city:" << location.city () << Endl; } if (Location.has_country_name ()) {Cerr << "" << location.country_name ( ) << Endl; } if (Location.has_altitude ()) { Cerr << "Altitude:" << location.altitude () << Endl; Cerr << "Longitude:" << location.longitude () << Endl; Cerr << "Latitude:" << location.latitude () << Endl; } if (Location.has_horizontal_accuracy ()) {Cerr << "horizotal accuracy:" << locat Ion.horizontal_accuracy () << Endl; } if (Location.has_region_code ()) {Cerr << "region code:" << location.region_cod E () << Endl; } if (Location.has_region_name ()) {Cerr << "region name:" << Location.region_nam E () << Endl; } if (Location.has_zip_postal_code ()) {cerr << "Zip postal code:" << Location.zi P_postal_code () << Endl; } } ....}
We print to see the location information we receive. Run on the phone and execute the following commands on the desktop at the same time:
We can see the location information we need. With this information, we can use it in our scope.
All the source code can be found at the following address:
BZR BranchLp:~liu-xiao-guo/debiantrial/scope
How to get location address information in Ubuntu scope