首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

输入地址获取地图坐标

2012-09-19 
输入地址获取map坐标根据地址获取坐标主要还是通过googlemap的API提供的服务 ,利用过webservice?获取数据。

输入地址获取map坐标

根据地址获取坐标主要还是通过googlemap的API提供的服务 ,利用过webservice?获取数据。

?

?

1 ?map服务地址:mapBaseUrl = "http://maps.google.com/maps/api/geocode/xml?address=";

?

2 ?提交数据 ??try {

? ? ? ? ? ? ? ?/* Connect to proxy service server */

? ? ? ? ? ? ? ?ClientConfig clientConfig = new DefaultClientConfig();

? ? ? ? ? ? ? ?Client client = Client.create(clientConfig);

? ? ? ? ? ? ? ?WebResource webResource = client.resource(uri);

? ? ? ? ? ? ? ?str = webResource.get(String.class);

? ? ? ? ? ?} catch (UniformInterfaceException e) {

? ? ? ? ? ? ? ?/* Print error to error log */

? ? ? ? ? ? ? System.out.println("Error occours in connect to google map service.");

? ? ? ? ? ?}

?

3 ? ? ? ? ? ? ? 处理数据

?? ? ? ? ? ? ? ? ? Document doc = XMLUtils.stringToXML(str);

? ? ? ? ? ?NodeList nl = doc.getElementsByTagName("location").item(0).getChildNodes();

? ? ? ? ? ?Coordinate co = new Coordinate();

? ? ? ? ? ?for (int i = 0; i < nl.getLength(); i++) {

? ? ? ? ? ? ? ?Node nd = nl.item(i);

? ? ? ? ? ? ? ?if (nd.getNodeName().equalsIgnoreCase("lat")) {

? ? ? ? ? ? ? ? ? ?co.setLatitude(new BigDecimal(nd.getTextContent()));

? ? ? ? ? ? ? ?}else if(nd.getNodeName().equalsIgnoreCase("lng")){

? ? ? ? ? ? ? ? ? ?co.setLongitude(new BigDecimal(nd.getTextContent()));

? ? ? ? ? ? ? ?}

? ? ? ? ? ?}

? ? ? ? ? ?return co;

?

?

热点排行