从我的应用程序使用基于位置的服务 - Android

时间:2011-06-23 14:13:04

标签: android gps location point-of-interest

我想向用户展示本地兴趣点。 由于这不是我的应用程序的主要目标,我希望找到一个相当简单的解决方案,例如将用户发送到Google商家信息或任何其他基于位置的应用。

有没有办法做到这一点? 如果答案是否定的,我怎么能这样做?也许使用一些API?

由于

2 个答案:

答案 0 :(得分:3)

您可以使用android位置和地图api记录here。如果没有,您可以随时调用地图意图,但必须确保在使用谷歌地图之前安装谷歌地图。以下是使用链接here的Android dev页面中的Location api的示例:

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
      makeUseOfNewLocation(location);
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

现在使用Google API here注册您的应用程序。获得API密钥后,您可以使用https://maps.googleapis.com/maps/api/place/search/json?location=&radius=&types=&name=&sensor=&key=YOUR_API_KEY的http请求。

您可以从google maps api site here找到每个参数的定义,但这只是一个小列表:

location (required) — The latitude/longitude around which to retrieve Place information. This must be provided as a google.maps.LatLng object.
radius (required) — The distance (in meters) within which to return Place results. The recommended best practice is to set radius based on the accuracy of the location signal as given by the location sensor. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area.
types (optional) — Restricts the results to Places matching at least one of the specified types. Types should be separated with a pipe symbol (type1|type2|etc). See the list of supported types.
language (optional) — The language code, indicating in which language the results should be returned, if possible. See the list of supported languages and their codes. Note that we often update supported languages so this list may not be exhaustive.
name (optional) — A term to be matched against the names of Places. Results will be restricted to those containing the passed name value. When a name is included, the area being searched may be broadened, to ensure a suitable number of results.
sensor (required) — Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. This value must be either true or false.
key (required) — Your application's API key. This key identifies your application for purposes of quota management and so that Places added from your application are made immediately available to your app. Visit the APIs Console to create an API Project and obtain your key.

这是android中的一个快速HTTP请求示例:

HttpGet myGet = new HttpGet("https://maps.googleapis.com/maps/api/place/search/json?location=&radius=&types=&name=&sensor=&key=YOUR_API_KEY");

获得返回结果后,您可以使用任何json库(例如来自here的google-gson)解析响应。

赖安

答案 1 :(得分:0)

您的问题不明确,但根据您的问题,我可以知道您想显示用户感兴趣的位置,如果我错了,请更正。

如果你想要那么

1)你需要那些点的纬度和经度  为此你可以使用任何API,你可以从你的webservice

获取

2)获取纬度和经度列表后,您可以使用项目覆盖

在地图上显示这些列表