实现在google map上搜索某一个中心点附近的餐馆,加油站等分类地点信息。
很简单,google的web server提供了这些数据。发送web request,中心点坐标location,地点属性types。会返回一个数据包,按照请求会返回json或者xml格式的数据,自己解析就可以了。下面的例子是json数据格式。
public static void getPlaces() throws Exception{
String s = "https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyAlg48onHHHcqT2QvrE6tEMrPF_rMKM4nA";URL url = new URL(s);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(6*1000);
String line;
StringBuilder builder = new StringBuilder();
if(conn.getResponseCode()== 200){
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while (( line = reader.readLine()) != null )
{
builder.append(line);
}
}
JSONObject json = new JSONObject(builder.toString());
.............................
}
jsonObject.getJSONArray(name);//解析里面关于坐标的数据。
reference: http://code.google.com/apis/maps/documentation/places/
本文介绍如何使用Google Maps API搜索指定中心点附近的餐馆、加油站等地点信息。通过发送WebRequest并指定中心点坐标及地点类型,API将返回JSON或XML格式的数据,便于进一步解析和利用。
4471

被折叠的 条评论
为什么被折叠?



