36

現在地を取得して、ユーザーの近く(1km以内)の場所の情報を表示したいアプリを開発したい..

たとえば、Android デバイスの現在の位置に関連する 1 km 以内にあるレストラン、ショッピング モール、病院に関する情報を表示したいとします。

私はこのリンクを通過しました:Using Google Places API in Android ..しかし、それ以上は得られませんでした。

AndroidでGoogle Places APIを使用した人はいますか?

4

5 に答える 5

25

心に留めておくべきいくつかの点:

  • Google の Places API を使用するには、Google マップの API キーを登録して取得する必要があります。
  • チュートリアルのクラス UrlSigner の変数の説明は次のとおりです。keyString=> は Google マップの API キーです。urlStringAPI キーを使用して署名する URL です。
  • コードでは、 と が見つかりinputKeyますinputUrl。これら 2 つの変数はテスト目的のためのものであり、必要に応じて省略できます。次のようにコードを直接記述できます。

    URL url = new URL(urlString);

    UrlSigner signer = new UrlSigner(keyString);

    String request = signer.signRequest(url.getPath(),url.getQuery());

    System.out.println("Signed URL :" + url.getProtocol() + "://" + url.getHost() + request);

UrlSigner クラスの main メソッド内。

于 2011-04-24T17:24:10.980 に答える
12

API はインドでうまく機能します (もちろん、世界中のどこでも機能します)。通過する必要があるのはGoogle Places APIです。ユーザーの現在の場所と希望する場所の種類を指定して、Google に URL リクエストを送信するだけです。

応答は、要求に応じて XML または Json のいずれかになります。あなたがしなければならないのは、それを解析することだけです。あなたの周りの場所を最大 50 km まで取得できます。URL リクエストの例は次のとおりです。

https://maps.googleapis.com/maps/api/place/search/xml?location=9.934866,76.267235&radius=50000&types=country%7Cairport%7Camusement_park%7Cbank%7Cbook_store%7Cbus_station%7Ccafe%7Ccar_rental%7Ccar_repair%7Cchurch%7Cdoctor%7Cfire_station%7Cfood%7Chindu_temple%7Chospital%7Clawyer%7Clibrary%7Cmosque%7Cmuseum%7Cpark%7Cparking%7Cpharmacy%7Cpolice%7Cpost_office%7Crestaurant%7Cschool%7Ctrain_station%7Czoo&sensor=true&key=your_API_Key

*注意: %7C は単に "|" です。

于 2012-02-07T09:50:19.127 に答える
4

GooglePlacesAPIは数週間前に公開されました。

Android互換のGoogleAPIクライアントライブラリforJavaを使用すると、AndroidランタイムからGooglePlacesAPIを使用できます。

Google Places APIRESTAPIは十分に文書化されています。Java用のGoogleAPIクライアントライブラリとGooglePlacesAPIの使用例については、次のブログエントリを確認してください。

http://ddewaele.blogspot.com/2011/05/introducing-google-places-api.html

于 2011-05-30T09:20:26.393 に答える
1

このチュートリアルはほぼ 1 年前に作成されたことを覚えておいてください。それ以来、Places API は一般公開されているため、登録プロセスははるかに簡単になりました。次のドキュメントを参照してください: http://code.google.com/apis/maps/documentation/places/#Limits

また、100 を超えるさまざまなカテゴリが提供されているカテゴリによる検索や、オートコンプリート サービスなど、現在利用可能な新機能もあります: http://code.google.com/apis/maps/documentation/places/autocomplete.html

特に、カテゴリ検索は、レストラン、ショッピング モール、病院を具体的に見つけるのに役立ちます。

于 2011-05-19T00:30:50.107 に答える
0
/*
For google api key:-
login to your mail account
go to https://code.google.com/apis/console/
goto services tab
click on places api and google map api button. Fill the details
goto api access tab and copy your google api key
*/



package com.example.jstest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;

public class MainActivity extends Activity {
    private String googleAPIKey = "your google api key"; 
    DefaultHttpClient client;
    HttpResponse res;
    HttpGet req;
    InputStream in;
    JSONObject jsonobj;
    JSONArray resarray;
    String requesturl;
    HttpEntity jsonentity;

    final String TAG = getClass().getSimpleName();  


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        requesturl="https://maps.googleapis.com/maps/api/place/search/json?radius=500&sensor=false&key="+googleAPIKey+"&location=13.01,74.79";

        System.out.println("Request "+requesturl);
        client=new DefaultHttpClient();
        System.out.println("hello");

        req=new HttpGet(requesturl);
        System.out.println("hello");

        try {
            res=client.execute(req);
            StatusLine status = res.getStatusLine();
            int code = status.getStatusCode();
            System.out.println(code);
            if(code!=200)
            {
                System.out.println("Request Has not succeeded");
                finish();
            }

            jsonentity=res.getEntity();
            in = jsonentity.getContent();

            jsonobj=new JSONObject(convertStreamToString(in));


            resarray = jsonobj.getJSONArray("results");

            if(resarray.length()==0){
            }
            else{
                int len=resarray.length();
                for(int j=0;j<len;j++)
                {
                    Toast.makeText(getApplicationContext(), resarray.getJSONObject(j).getString("name") , Toast.LENGTH_LONG).show();
                }
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }   
        catch (JSONException e) {
            e.printStackTrace();
        }   
    }

    private String convertStreamToString(InputStream in) {
        BufferedReader br=new BufferedReader(new InputStreamReader(in));
        StringBuilder jsonstr=new StringBuilder();
        String line;
        try {
            while((line=br.readLine())!=null)
            {
                String t=line+"\n";
                jsonstr.append(t);
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return jsonstr.toString();
    }  

}
于 2013-10-01T15:12:35.910 に答える