views:

132

answers:

1

I am trying to use the Google Earth API to create a simple view of the globe with a search field in which the user can type a location. When they hit go, the globe will zoom in on the location they typed in.

I would like the view to be looking straight down on the location they specified. I have tried the following code:

var lookAt = ge.createLookAt('');
lookAt.set(point.y, point.x, 600, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 00, 0);
ge.getView().setAbstractView(lookAt);

But this always goes to slightly the wrong location,

A: 

Could it be simply that you have point.y and point.x the wrong way around?

// latitude, longitude, altitude, altitudeMode, heading, tilt, range
lookAt.set(point.x, point.y, 600, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 0);

Failing that, when you say 'the user can type a location' do you mean you are geocoding an entry? For example are the users entering "New York" or "M20 1LL" for example? If so you should realise that geocoding is not an exact science and that the results are not always accurate (especially with free geocoding services).

There are two real solutions if this is the case;

1) Pay to use a commercial geocoding service to guarantee accuracy.

2) Build your own database or cache that contains pre-computed geocoder responses of 'key' places. http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding_Caching

BTW the code looks AOK...apart from the double zero (00) for the tilt...

var lookAt = ge.createLookAt('');

// latitude, longitude, altitude, altitudeMode, heading, tilt, range
lookAt.set(point.y, point.x, 600, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 0);

ge.getView().setAbstractView(lookAt);
Fraser