输入地址获取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;
?
?