是否可以使用Android TV的Google Maps Geolocation API? [英] Is it possible to use Google Maps Geolocation API for Android Tv?

查看:171
本文介绍了是否可以使用Android TV的Google Maps Geolocation API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个适用于android TV的应用程序,该应用程序已经在Google Play商店中运行良好.

I was created one application for android TV which is already in Google Play store and works fine.

现在,我的新要求是在Android TV中使用 Google Maps Geolocation API ,因此我被推荐为此链接,但没有运气.

Now my new requirement is to use the Google Maps Geolocation API in Android TV so I was refereed this link but no luck.

所以我的问题是,可以在Android TV中使用 Google Maps Geolocation API吗?

So my question is that Is it possible to use Google Maps Geolocation API in Android TV?

推荐答案

经过大量研究,最终我得到了答案.是的,可以在Android TV中使用 Google Maps Geolocation API ,但存在一定的局限性.根据Google Maps Geolocation API提供的文档,它们主要是实现此目的的两种方法

After many research finally I got the answer.Yes it is possible to use Google Maps Geolocation API in Android TV but with some limitation.As per the documentation given by the The Google Maps Geolocation API their are mainly Two way to achieve this

1)使用手机信号塔.

1) Using Cell tower.

2)使用WiFi接入点.

2) Using WiFi Access Points.

现在,对于课程的第一种方式,这是不可能的,因为Android TV没有呼叫或SIM卡功能,因此它无法连接到Cell Tower,因此无法正常工作.

Now, For the 1st way ofCourse it is not possible because Android TV do not have Calling or SIM facility so it can not connect to Cell Tower so it is not working.

现在,对于第二种方式,它很有趣.我正在研究这个东西,最终成功实现了这个东西.我注意到的另一件事是,并且在文档中还给出了使用IP地址将提供比Cell Tower和WIFI接入点更高的准确率.因此,我考虑了WIFI接入点和"considerIp":"true" 以获得最高的准确率.

Now, For the 2nd way it is quite interesting. I was research on this thing and finally Successfully implemented this thing. Another thing I noticed that and also given in the documentation that using IP address it will give the highest accuracy ratio then the Cell Tower and WIFI access points.So, I consider both WIFI access points and "considerIp": "true" for highest accuracy ratio.

经过大量研究后,我的实际任务是实现此功能,因为我知道如何获取WIFI接入点,所以对我来说很容易实现.因此,我使用以下方法来获取WIFI接入点.

After this much of research my actual task is to implement this thing it is quite easy for me to implement this because I know how to get the WIFI Access Points.So, I used the following way to get WIFI Access Points.

List<ScanResult> results;
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
results = wifiManager.getScanResults();

    String message = "No results found.Please Check your wireless is on";
    if (results != null)
    {
        final int size = results.size();
        if (size == 0)
            message = "No access points in range";
        else
        {
            ScanResult bestSignal = results.get(0);
            int count = 1;
            for (ScanResult result : results)
            {
                if (WifiManager.compareSignalLevel(bestSignal.level, result.level) < 0)
                {
                    bestSignal = result;
                }
            }
        }
    }
    Toast.makeText(this, message, Toast.LENGTH_LONG).show();

获取WIFI接入点列表后,创建一个传递调用API的JSONObject "https://www.googleapis.com/geolocation/v1/geolocate?key=your_key" .我被Volley调用了此API.用于创建包含WIFI接入点的JSONObject这就是我的习惯.

After getting list of WIFI Access Points create a JSONObject which Pass to Call the API "https://www.googleapis.com/geolocation/v1/geolocate?key=your_key".I was used Volley to call this API.For creating the JSONObject which contains WIFI Access points here is the way which I was used.

JSONObject parent;
try {
        parent = new JSONObject();
        parent.put("considerIp", false);
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject;
        for (int i = 0; i < results.size(); i++) {
            jsonObject = new JSONObject();
            jsonObject.put("macAddress", results.get(i).BSSID);
            jsonObject.put("signalStrength", results.get(i).level);
            jsonObject.put("signalToNoiseRatio", 0);
            jsonArray.put(jsonObject);
            System.out.println("jsonObject: " + jsonObject.toString(4));
        }
        parent.put("wifiAccessPoints", jsonArray);
        Log.d("output", parent.toString());
        System.out.println("parenttttt: " + parent.toString(4));
        txt_request.setText(parent.toString(4));
    } catch (JSONException e) {
        e.printStackTrace();
    }

在上面的代码中,我使用了"parent.put(" considerIp,false)",使用false的原因仅是检查是否使用WIFI接入点获得了准确的结果.正确并查看结果如何.

From the above code I was used "parent.put("considerIp", false)" the reason behind use false was nothing but just to checked whether I got the accurate result using WIFI Access Points or not.You can make it true and see the result what you get.

成功响应后,您会得到一个结果,该结果给出了纬度和经度以及准确度比,该比值显示了结果的准确性.您得到了诸如此类的响应.

After successful response you got the result which gives the Latitude and Longitude with the Accuracy ratio which shows how accurate the result was.You got the response something like this.

{
  "location":
  {
     "lat": your latitude,
     "lng": your longitude
  },
 "accuracy": How accurate the result was [like 1523, 1400.25 etc.]
}

这就是在Android TV中实现Google Maps Geolocation API的方法.

This is the way to achieve Google Maps Geolocation API in Android TV that's it.

这篇关于是否可以使用Android TV的Google Maps Geolocation API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆