So lets start to stealing some information from Google Database. I am using Great JAVA technology toread the Google map link and retrieve the required information.
Below is the code which show the latitude and longitude of any point which you Enter...
----------------------------------------- Start code ------------------------------------------------------
----------------------------------------- End code ------------------------------------------------------import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.StringTokenizer;
/**
*
* @author noman.sadiq
*
*
*/
public class GoogleFun {
String Latitude;
String Longitude;
public void findLatLong(String City) {
try {
City=City.replaceAll(" ", "+");
String url = "http://maps.google.com/maps/geo?q="+City+"&+output=xml&oe=utf8\""
+ "&sensor=false&key=ABQIAAAAVu6FLnwHDZ7nt0cmZfpnmRQVl2aZopxmRHQArsVnI0wW3Lv2qhQYvEEjT-yKshCHcutI9eBuDiqrIQ";
URL urlcon = new URL(url);
HttpURLConnection uc = (HttpURLConnection) urlcon.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc
.getInputStream()));
String inputLine;
StringBuffer bf = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
bf.append(inputLine + "\n");
}
in.close();
StringTokenizer st = new StringTokenizer(bf.toString());
while (st.hasMoreTokens()) {
if (st.nextToken().startsWith("\"coordinates\"")) {
st.nextToken();
this.setLongitude(st.nextToken().replaceAll("/", ""));
this.setLatitude(st.nextToken().replaceAll(",", ""));
break;
}
}
} catch (Exception t) {
t.printStackTrace();
}
}
/**
*
* @return
*/
public String getLatitude() {
return Latitude;
}
/**
*
* @param latitude
*/
public void setLatitude(String latitude) {
Latitude = latitude;
}
/**
*
* @return
*/
public String getLongitude() {
return Longitude;
}
/**
*
* @param longitude
*/
public void setLongitude(String longitude) {
Longitude = longitude;
}
public static void main(String a[]) {
String Location="F-10/1 street 31 house 255 islamabad";
GoogleFun ob =new GoogleFun();
ob.findLatLong(Location);
System.out.println("Latitude: "+ob.getLatitude()+" Longitude: "+ob.getLongitude());
}
}
enjoy Google with Java..

No comments:
Post a Comment