Reputation: 3964
I am writing a small page to display locations on Google Maps. What I was aiming at was a pushpin for each location that I can click on and it will popup with a steetview of that address.
I have got all the code working but I am getting streetviews for addresses different to the addresses I am sending.
For example.
When I search for "Edwards Buildbase, Scotland Road, Market Harborough, LE16 8AX" in a browser, Google returns a streetview right outside the premises! Perfect! Just what I wanted!
But, in my code, what I do is...
Geocode the address "Edwards Buildbase, Scotland Road, Market Harborough, LE16 8AX" and then tell the steetview that the lat/longs it should go to are the results....
And I end up with different streetviews!
This is my geocode function
var address = kmlEvent.featureData.name + ", " + kmlEvent.featureData.description;
geocoder.geocode({ 'address': address }, function (results, status) {
var latlng = results[0].geometry.location;
var panoramaOptions = {
position: latlng,
pov: {
heading: 34,
pitch: 10
}
};
This is what I end up with when I click on Edwards Buildbase...
This is what I see in a browser...
I am guessing that because I am geocoding the address and then telling the streetview to focus on a lat/long there is a difference.
This is my demo site if you want to have a closer look at the code
http://googlemap.azurewebsites.net/
Does anyone know the best way to get the images being returned from the browser search please?
Any help would be appreciated!
Trev
Upvotes: 0
Views: 123
Reputation: 161334
The address in you are geocoding is: "Edwards Buildbase, Scotland Road, Market Harborough, LE16 8AX", that returns a location for "Scotland Road, Market Harborough, Leicestershire LE16, UK" (52.4726594, -0.9118068000000221), which is not what you are looking for.
If you use the Places API (Edwards Buildbase is not an address, it is a place), it returns a better result (52.470992, -0.9135619999999562):
Another option would be to use "17 Scotland Road, Market Harborough, Leicestershire LE16 8AX, UK"
However, you would probably be better off correcting the coordinates in the KML and using those for the streetview, as both the places API and the geocoding service are subject to rate limits and a quota.
Upvotes: 1