-
根据地名获取经纬度
1.
根据
goole
api
得到经纬度:
String
strUrl=
URL url;
InputStream in = null;
String str =
String lnglat =
try {
url
= new URL((strUrl, strCurrent));
URLConnection uc = nnection();
in = utStream();
/*Object obj = tent();
InputStream in = (InputStream) obj;*/
byte[] tt = new byte[ble()];
int z;
while ((z =
(tt, 0, )) != -1) {
str
= new String(tt,
//n(str);
}
();
}
catch (MalformedURLException e) {
tackTrace();
} catch(SocketException e)
{
lnglat =
n((i) +
} catch (IOException e) {
tackTrace();
}
if(str !=
lnglat = getString(str);
n((i) +
}
try {
(1000);
}
catch (InterruptedException e) {
tackTrace();
}
public static String
getLngAndLat(InputStream instream) {
DocumentBuilderFactory dbf
= tance();
DocumentBuilder db = null;
try {
db = umentBuilder();
} catch
(ParserConfigurationException e) {
tackTrace();
}
Document doc = null;
try {
doc =
(instream);
}
catch (SAXException e) {
tackTrace();
} catch (IOException e) {
tackTrace();
}
Element root =
umentElement();
NodeList points =
mentsByTagName(
String lnglat =
for(int i=0;i
Element point =
(Element)(i);
lnglat = ribute(
}
return lnglat;
}
public static String
getString
(String xmlString)
{
int a =
f(
int b =
f(
int c =
f(
int d =
f(
String lat =
ing(a+5, b);
String lng = ing(c + 5, d);
return lng +
}
2.
根据
“百度
API
”得到地名的经纬度:
Html
代码是: