简体   繁体   English

在非活动java类中使用适用于Android的Fused Location提供程序,并在主Activity类中获取经度和纬度

[英]Using Fused Location provider for android in a non activity java class and get longitude and latitude in main Activity class

I want to use fused location provider in my android application and get the current users location longitude and latitude and pass it as a map link in text message. 我想在我的Android应用程序中使用融合位置提供程序,并获取当前用户位置的经度和纬度,并将其作为文本消息中的地图链接传递。

I used this example FusedLocation Example to get long and lat coordinates of location but in my case i want to put all fusedLocation functions in a java class which is a non activity class and call it from main activity class to get long and lat , 我使用这个示例FusedLocation Example获取位置的longlat坐标,但在我的情况下,我想将所有fusedLocation函数放在一个非活动类的java类中,并从主活动类调用它来获取longlat

since ima beginner in android and i searched alot to find something like this but couldn't get a example or tutorial. 因为在Android中的ima初学者我搜索了很多这样的东西,但无法得到一个例子或教程。

can anybody help me in this or advice me if its the better solution to retrieve location coordinates and address from any provider working in any situations? 任何人可以帮助我或建议我,如果它是从任何情况下工作的任何提供商检索位置坐标和地址的更好的解决方案?
thanks in advance 提前致谢

That is quite possible - in fact you can take a look at this Gist that I created. 这很有可能 - 事实上你可以看看我创造的这个要点 Essentially, the "non-Activity" class that you use, should implement the Location-Service Connection Listeners GoogleApiClient.ConnectionCallbacks , GoogleApiClient.OnConnectionFailedListener (or receive instance of GoogleApiClient as parameter), and also the LocationListener -you may also want to pass the Context object to the constructor of that class (which will be the activity's context). 基本上,您使用的“非活动”类应该实现位置 - 服务连接监听器GoogleApiClient.ConnectionCallbacksGoogleApiClient.OnConnectionFailedListener (或接收GoogleApiClient实例作为参数),以及LocationListener - 您也可能希望传递Context对象到该类的构造函数(它将是activity的上下文)。 Here is Gist which provides an example of implementing a LocationListener . 这是Gist ,它提供了实现LocationListener的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM