java可以调用google map api吗?

化外之民 2009-07-13 07:51:40
问题是这样的:我想使用google地图的反向地址解析功能,提供一个经纬度得到对应地址,在js中是可以实现的,但是因为有太多的地址需要解析,我需要放在java后台代码中处理,请教该如何做?
谢谢!
...全文
4341 35 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
35 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝少飞 2012-07-17
  • 打赏
  • 举报
回复
200是什么意思啊
  • 打赏
  • 举报
回复
楼主调用Google Map API 用java写一个地图的demo有没 小菜我没有接触过这个 啥都不会 求教啊
长笛党希望 2011-07-28
  • 打赏
  • 举报
回复
js做的倒是不错。。。
georgelife7 2010-12-07
  • 打赏
  • 举报
回复
直接输入网址:http://maps.google.com/maps/geo?output=xml&key=abcdefg&q=37.4419,-122.1419
就可以得到xml信息呀,
那GOOGLE MAP API 怎么用啊?

hzz1988 2010-09-23
  • 打赏
  • 举报
回复
学习了·
zhanmingbo 2010-07-20
  • 打赏
  • 举报
回复
关注一下
aiwuhui 2010-04-14
  • 打赏
  • 举报
回复
都这么牛啊,关注中... (在swing里可以调用API吗)
freeVickie 2009-12-18
  • 打赏
  • 举报
回复
好了不起啊 这么简洁地实现了解析地址的功能 佩服!!!!!!
zhaoxuanyi 2009-12-03
  • 打赏
  • 举报
回复
牛逼,非常感谢
化外之民 2009-07-16
  • 打赏
  • 举报
回复
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import com.sun.net.ssl.HttpsURLConnection;


public class testHttp {
public static void main(String[] args){
URL myURL = null;
try {
myURL = new URL("http://maps.google.com/maps/geo?output=xml&key=abcdefg&q=38.9146943,121.612382");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
URLConnection httpsConn = null;
try {
httpsConn = (URLConnection) myURL.openConnection();

InputStreamReader insr = new InputStreamReader(httpsConn.getInputStream());
int respInt = insr.read();
while (respInt != -1) {
System.out.print((char) respInt);
respInt = insr.read();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
化外之民 2009-07-16
  • 打赏
  • 举报
回复
采用发送HTTP请求的方式,返回xml内容中的地址为什么会是英文的?

URL myURL = null;
try {
myURL = new URL("http://maps.google.com/maps/geo?output=xml&key=abcdefg&q=38.9146943,121.612382");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
URLConnection httpsConn = null;
try {
httpsConn = (URLConnection) myURL.openConnection();

InputStreamReader insr = new InputStreamReader(httpsConn.getInputStream());
int respInt = insr.read();
while (respInt != -1) {
System.out.print((char) respInt);
respInt = insr.read();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


化外之民 2009-07-16
  • 打赏
  • 举报
回复
就是LS这个了,
改成String url = "http://ditu.google.cn/maps/geo?output=csv&key=abcdef&q=29.840644,111.093750");
idilent 2009-07-16
  • 打赏
  • 举报
回复
直接调用中文地图,ditu.google.cn
化外之民 2009-07-16
  • 打赏
  • 举报
回复
代码改成如下,运行得到的地址是英文的:200,4," , Changde, Hunan, China"
但是在浏览器上直接运行http://maps.google.com/maps/geo?output=csv&key=abcdef&q=29.840644,111.093750得到的却是中文的:200,4,"中国湖南省常德市石门县"
我需要在程序中运行,怎么让它也得到中文地址?是另外要设置什么吗?

String url = String.format(
"http://maps.google.com/maps/geo?output=csv&key=abcdef&q=29.840644,111.093750);
URL myURL = null;
URLConnection httpsConn = null;
try {
myURL = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}

try {
httpsConn = (URLConnection) myURL.openConnection();
InputStreamReader insr = new InputStreamReader(httpsConn.getInputStream(),"UTF-8");
BufferedReader br = new BufferedReader(insr);
String data = null;
if((data = br.readLine())!=null)
{
System.out.println(data);

}

} catch (IOException e) {
e.printStackTrace();
}
xuexijava 2009-07-16
  • 打赏
  • 举报
回复
关注学习加顶
ximao0529 2009-07-16
  • 打赏
  • 举报
回复
同意21楼, 使用GeoCode
化外之民 2009-07-15
  • 打赏
  • 举报
回复
发现上面的方法要不得,因为这种程序要求所有的类都要创建在client包下面,不然它就不认,而且要求提供类名.gwt.xml文件,真是见鬼了,我要那么多业务逻辑要处理还要引入其他包,根本就行不通。
化外之民 2009-07-15
  • 打赏
  • 举报
回复
目前我用Google Maps Library for GWT写了个程序可以用java代码解析地址,可惜不能整合到现有项目中,因为这个程序离不开GWT环境,只能在windows上运行,感觉有点不伦不类。如果没有更好办法的话也就只能这么做了。
附测试代码:

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.maps.client.geocode.Geocoder;
import com.google.gwt.maps.client.geocode.LocationCallback;
import com.google.gwt.maps.client.geocode.Placemark;
import com.google.gwt.maps.client.geocode.StatusCodes;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.user.client.Window;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class GpsServer implements EntryPoint {

/**
* This is the entry point method.
*/
public void onModuleLoad() {
getAddr(24.9767616666667,117.559905);
}

private void getAddr(Double Latitude, Double longitude) {
LatLng latLng = LatLng.newInstance(Latitude, longitude);
Geocoder gc = new Geocoder();
gc.getLocations(latLng, new LocationCallback() {
//@Override
public void onFailure(int statusCode) {
Window.alert("Failed to geocode position " + ". Status: "
+ statusCode + " " + StatusCodes.getName(statusCode));
}

//@Override
public void onSuccess(JsArray<Placemark> locations) {
StringBuilder value = new StringBuilder();
for (int i = 0; i < locations.length(); ++i) {
Placemark location = locations.get(i);
if (location.getAddress() != null ) {
value.append(location.getAddress() +location.getAccuracy()+ "\r\n");
}
}
final String addr = value.toString();
Window.alert(addr);
}
});

}
}
yyh84yangtao 2009-07-15
  • 打赏
  • 举报
回复
顶!很强大啊,密切关注!
海会圣贤 2009-07-15
  • 打赏
  • 举报
回复
很强大啊。
加载更多回复(15)

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧