如何在我的笔记本电脑上获取我当前的位置 - Java 程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22032062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get my current Location on my laptop - Java program
提问by user584910
As Google latitude is no more.
由于谷歌纵横已不复存在。
I am writing a java program that get users current location on laptop computer. IP address does not return accurate place and Currently built-in GPS receiver are not common in laptops. I want to use my Android smart phone to send/sync user's current location to my java based program in laptop.
我正在编写一个 java 程序,用于获取用户在笔记本电脑上的当前位置。IP 地址不返回准确的位置,目前内置 GPS 接收器在笔记本电脑中并不常见。我想使用我的 Android 智能手机将用户的当前位置发送/同步到我在笔记本电脑中基于 java 的程序。
How would I do this via Bluetooth.
我将如何通过蓝牙做到这一点。
If you have any other ideas to get current location of the user then please also share.
如果您有任何其他想法来获取用户的当前位置,也请分享。
[edited]
[编辑]
回答by class
There is not an API for location within Google+. You can use the Google Maps Places APIto get information of interest located close to a user. Before you can make API queries to the Google Maps Places API, you will need geolocation data (latitude and longitude) to make your queries.
Google+ 中没有用于位置的 API。您可以使用Google Maps Places API来获取靠近用户的感兴趣的信息。在您可以对 Google Maps Places API 进行 API 查询之前,您需要地理定位数据(纬度和经度)来进行查询。
For getting GPS data from the user's laptop, there are a number of approaches, however, I personally prefer to use a location database and perform lookups on the user's IP. The GeoLite databases from Maxmindare really easy to use: you get the user's IP address and then query the database for the location (specificity will vary based on the database used) and the location data will include anything you need for mapping purposes. This stack overflow question on geolocationincludes a link to some example code that should get you bootstrapped.
为了从用户的笔记本电脑获取 GPS 数据,有多种方法,但是,我个人更喜欢使用位置数据库并在用户的 IP 上执行查找。该从的MaxMind GEOLITE上的数据库是很容易使用:你得到了用户的IP地址,然后在数据库中查询位置(特异性会根据所使用的数据库)和位置数据将包括任何你需要的映射的目的。这个关于地理定位的堆栈溢出问题包括一些示例代码的链接,可以让您进行引导。
You may also want to consider the geolocation API for modern browsersif you're using a web integration on the desktop.
如果您在桌面上使用 Web 集成,您可能还需要考虑用于现代浏览器的地理定位 API。
Once you have lat/long coordinates, you can get location data using the Places API by passing in the coordinates to Place search APIs.
获得纬度/经度坐标后,您可以使用 Places API 通过将坐标传递给 Place 搜索 API来获取位置数据。
If you want to get location data from Android, you should use a location provider to set up location status updates. The Android documentation does a better job explaining the steps than I can here.
如果您想从 Android 获取位置数据,您应该使用位置提供程序来设置位置状态更新。Android 文档在解释步骤方面做得比我在这里做得更好。
To transmit the data to your computer, you can use bluetooth.
要将数据传输到您的计算机,您可以使用蓝牙。
回答by Ameya Chavan
There is one other way to achieve it using java only.
还有另一种方法可以仅使用 java 来实现它。
You can use selenium+PhantomJS to hit "https://mycurrentlocation.net/". This website by default will load you current location and you can read the data on this website using Selenium API.
您可以使用 selenium+PhantomJS 来点击“ https://mycurrentlocation.net/”。本网站默认会加载您当前的位置,您可以使用 Selenium API 读取本网站上的数据。
PhantomJS is an invisible browser, it can open any website in invisible mode and read data from the same.
PhantomJS 是一个隐形浏览器,它可以在隐形模式下打开任何网站并从中读取数据。
Hope this helps.
希望这可以帮助。