I have used the sample code from the following URL. http://earth-api-samples.googlecode.com/svn/trunk/examples/geocoder.html
I would like to show the location after the page loads. I am new to google earth.
Right now, I have removed the location form and called the buttonClick function under the initCB method. It did not works.
Please help.
You have either to pass the city to the geocoder in the code or to get the latitude/longitude before and insert it in the code.
-1. First option
The example use Google Maps v.2 API, while now you have available v.3 here: https://developers.google.com/maps/documentation/javascript/geocoding
var address = "Los Angeles";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
point = results[0].geometry.location;
alert(point);//this is to see the lat long values
var lookAt = ge.createLookAt('');
lookAt.set(point.y, point.x, 10, ge.ALTITUDE_RELATIVE_TO_GROUND,
0, 60, 20000);
ge.getView().setAbstractView(lookAt);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
-2. Second option
var lookAt = ge.createLookAt('');
lookAt.set(50.5, -79.5, 10, ge.ALTITUDE_RELATIVE_TO_GROUND,
0, 60, 20000);
ge.getView().setAbstractView(lookAt);
where 50.5 should be the latitude and -79.5 should be the longitude.
Hope it helps!
Cheers, Mihai