Pages

Monday, April 11, 2011

GoogleMap - Latitude and Longitude

I have to display the map with respect to the place given.

In that tags the longitude and latitude of the location to be passed as parameters to get the exact location in Map.

I got many examples for displaying the Google map in different way & special effects. But not able to find how get the longitude and latitude of a location/place. At last found the way. Might help someone who searches like me.

Code: To get the Longitude & Latitude of the location

To have Google map in an application. We have to get a key from this link
http://code.google.com/apis/maps/signup.html



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;


try {

String locationName="johannesburg"; \\Give any location\place name
String gmapKey="ABQIAAAAiqblAQNWNoua1VYnGtU1dBRdtL7gCpXlU8FuabFvwIMVSlhRL4gzsM_7WZ6hbScCw1YuLXHNjwA"; \\Give your google map key
URL url = new URL("http://maps.google.com/maps/geo?q="+locationName+"&output=csv&key="+gmapKey);
URLConnection urlConnection = url.openConnection();
BufferedReader in;
String inputLine;
String data =null;

in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
while ((inputLine = in.readLine()) != null){
data =inputLine;
System.out.println("Accuracy,Status,Latitude,Longitutude of " +locationName+" >> "+data);
}
in.close();

}
} catch (IOException e) {
e.printStackTrace();
}


output:

Accuracy,Status,Latitude,Longitutude of johannesburg >> 200,4,-26.2041028,28.0473051

1 comment:

  1. In this manner my pal Wesley Virgin's report launches in this shocking and controversial video.

    You see, Wesley was in the military-and soon after leaving-he discovered hidden, "SELF MIND CONTROL" tactics that the government and others used to get everything they want.

    As it turns out, these are the EXACT same SECRETS many celebrities (notably those who "became famous out of nowhere") and top business people used to become rich and successful.

    You probably know how you use only 10% of your brain.

    Really, that's because most of your brainpower is UNCONSCIOUS.

    Perhaps this conversation has even taken place INSIDE your own head... as it did in my good friend Wesley Virgin's head seven years back, while riding an unregistered, beat-up trash bucket of a car without a license and with $3 on his debit card.

    "I'm so fed up with living check to check! When will I finally make it?"

    You took part in those conversations, ain't it right?

    Your own success story is going to happen. You just need to take a leap of faith in YOURSELF.

    Take Action Now!

    ReplyDelete