2012-05-27 63 views
2

最近的位置有沒有辦法根據一個特定的點(經度/緯度)找到在谷歌地圖最近的位置, 我讀到關於谷歌將API的一些事情,但我不知道如何使用它.. 是否有可能找到下一個最近的呢?查找谷歌地圖Android版

回答

-1

Google Places API

地址::

https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

需要緯度變化,長,半徑,類型,名稱和關鍵。

注::需要註冊的開發者預覽版。

+1

更多信息http://stackoverflow.com/questions/8428209/show-當前位置和附近地點和路線之間的兩個地方使用googl –

+0

開發人員預覽不再存在。 –

3

使用Google Places API Web Service你可以執行Places Search Request其中location是用戶緯度,經度:

https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&rankby=distance&types=food&sensor=false&key=AddYourOwnKeyHere

確保指定的,而不是radius參數rankby=distance參數,如果你想按照時間順序獲取最近的地點,而不是指定半徑內最顯眼的地方。

我也曾在上面只在我響應返回食物種類的地方請求指定的types=food參數。其他支持的類型可以找到here

要使用Google Places API Web Service,您需要按照說明here獲取使用該服務的API密鑰,該密鑰需要根據您的請求在key=AddYourKeyHere參數下發送。

如果您要在JavaScript應用程序中使用此服務,請查看Google Maps API v3Places Library

2

這裏是這樣,你可以實現它

LocationManager locationManager = (LocationManager) context 
        .getSystemService(Context.LOCATION_SERVICE); 
     LocationListener locationListener = new LocationListener() { 
      @Override 
     public void onStatusChanged(String provider, int status, 
       Bundle extras) { 
     } 

     @Override 
     public void onProviderEnabled(String provider) { 
     } 

     @Override 
     public void onProviderDisabled(String provider) { 
     } 

     @Override 
     public void onLocationChanged(Location location) { 
      Double l1 = location.getLatitude(); 
      Double l2 = location.getLongitude(); 
      address = GetAddress(l1, l2);    
     } 
    }; 
    locationManager.requestLocationUpdates(
      LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 

private String GetAddress(Double lat, Double lon) { 
    Geocoder geocoder = new Geocoder(context, Locale.ENGLISH); 
    String ret = ""; 
    List<Address> addresses = null; 
    try { 
     addresses = geocoder.getFromLocation(lat, lon, 1); 
     if (!addresses.equals(null)) { 
      Address returnedAddress = addresses.get(0); 
      StringBuilder strReturnedAddress = new StringBuilder("\n"); 
      for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) { 
       strReturnedAddress 
         .append(returnedAddress.getAddressLine(i)).append(
           "\n"); 
      } 
      ret = "Around: " + strReturnedAddress.toString(); 
     } else { 
      ret = "No Address returned!"; 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
     ret = "Location: https://maps.google.co.in/maps?hl=en&q=" + lat 
       + "," + lon; 
    } catch (NullPointerException e) { 
     e.printStackTrace(); 
     ret = lat + "," + lon; 
    } 
    return ret; 
} 

而且還AndroidManifest添加這些權限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />