开发者

Using location based services from my app - Android

开发者 https://www.devze.com 2023-03-14 18:44 出处:网络
I want to show local points of interest to the users. Since this isn\'t the main goal of my app, I wish to find a rather simple solution,like sending开发者_JAVA技巧 the user to Google Places or any ot

I want to show local points of interest to the users. Since this isn't the main goal of my app, I wish to find a rather simple solution,like sending开发者_JAVA技巧 the user to Google Places or any other location based app.

Is there a way of doing that? If the answer is no, how could I do that? Maybe using some API?

Thanks


You can use the android location and maps api documented here. If not, you can always call the Maps intent but you have to make sure google maps is installed before using it. Here is an example using the Location api from the android dev page linked here:

// 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);

Now register your application with google API here. Once you get your API key you can use an http request to https://maps.googleapis.com/maps/api/place/search/json?location=&radius=&types=&name=&sensor=&key=YOUR_API_KEY.

You can find the definition of each parameter from the google maps api site here but this is a little list:

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.

Here's a quick HTTP request example in android:

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

Once you got your return result, you can parse the response using any json library such as google-gson from here.

Ryan


Your question is not clear but from your question i am able to know that you want to display location of user interest correct me if i m wrong.

if you want to same then

1) you need latitude and longitude of that points for that you can use any API of you can get those from your webservice

2) after getting list of latitude and longitude you can display those on map by using Itemized Overlay

0

精彩评论

暂无评论...
验证码 换一张
取 消