我想向用戶顯示本地興趣點。 由於這不是我的應用程序的主要目標,我希望找到一個相當簡單的解決方案,例如將用戶發送到Google Places或任何其他基於位置的應用程序。從我的應用程序使用基於位置的服務 - Android
有沒有辦法做到這一點? 如果答案是否定的,我該怎麼做?也許使用一些API?
感謝
我想向用戶顯示本地興趣點。 由於這不是我的應用程序的主要目標,我希望找到一個相當簡單的解決方案,例如將用戶發送到Google Places或任何其他基於位置的應用程序。從我的應用程序使用基於位置的服務 - Android
有沒有辦法做到這一點? 如果答案是否定的,我該怎麼做?也許使用一些API?
感謝
您可以使用android位置和地圖API文檔here。如果沒有,您可以隨時致電Google地圖的意圖,但您必須確保在使用Google地圖之前先安裝Google地圖。下面是使用Location
API從Android開發人員網頁爲例鏈接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);
現在註冊與谷歌API here您的應用程序。一旦你得到你的API密鑰,你可以使用http請求https://maps.googleapis.com/maps/api/place/search/json?location=&radius=&types=&name=&sensor=&key=YOUR_API_KEY
。
你可以找到從谷歌地圖API的網站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),你需要緯度和那經度點 的,你可以用你的任何API獲得的列表後,可以得到那些從你的web服務
2)緯度和經度,你可以通過使用分項疊加顯示在地圖上的那些
謝謝,但是如果我需要顯示用戶附近的酒吧(例如)呢?我不認爲我可以使用默認的位置服務(糾正我,如果我錯了)。 – Tofira
那麼,在找到用戶位置後,您可以使用帶有HTTP請求的Google Maps API。有關更多詳情,請參見[此處](http://code.google.com/apis/maps/documentation/places/#PlaceSearches)。簡而言之,您將使用適當的參數(在上面的鏈接中定義)對https://maps.googleapis.com/maps/api/place/search/output?parameters進行http調用,該函數將返回一個json響應與附近的地方。如果您需要Android的示例代碼,請告訴我。要使這種方法起作用,您需要使用Google的註冊應用程序來傳遞請求中的密鑰。 – Ryan
謝謝,你真的幫了我。如果可能的話,我真的很喜歡示例代碼,它肯定會幫助我完成這項工作。感謝 – Tofira