怎么在Ubuntu Scope中获取location地址信息
Location信息对很多有地址进行搜索的应用来说非常重要。比如对dianping这样的应用来说,我们可以通过地址来获取当前位置的一些信息。在这篇文章中,我们来介绍如何获取Scope架构中的位置信息。这个位置信息可以对我们很多的搜索是非常重要的。
1)创建一个简单的Scope应用
2)加入代码获取Location信息
[ScopeConfig] DisplayName = Scopetest Scope Description = This is a Scopetest scope Art = screenshot.png Author = Firstname Lastname Icon = icon.png LocationDataNeeded=true [Appearance] PageHeader.Logo = logo.png
同时我们打开scope.cpp文件,并修改为:
#include <unity/scopes/SearchMetadata.h> // added .... void Query::run(sc::SearchReplyProxy const& reply) { try { 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() << 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: " << location.horizontal_accuracy() << endl; } if ( location.has_region_code() ) { cerr << "region code: " << location.region_code() << endl; } if ( location.has_region_name() ) { cerr << "region name: " << location.region_name() << endl; } if ( location.has_zip_postal_code() ) { cerr << "zip postal code: " << location.zip_postal_code() << endl; } } .... }
我们通过打印的方式来查看我们所收到的位置信息。在手机上运行,并同时在desktop上执行如下的命令:
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。