Street View Heading from Street Address

200 views
Skip to first unread message

volksman

unread,
Jun 7, 2010, 11:17:30 AM6/7/10
to Google Maps JavaScript API v3
Hello All!

I'm wondering if there is a way to get 'heading' information from a
street address. My maps feature specific street addresses and I'm
creating a custom control to allow people to see the address at street
level. But right now when they hit the control it just drops them in
a street view but heading north.

I get my Lat/Long from the geocoding service. Was wondering if there
is a way to get heading info from that service too.

I don't see any mention of it in the docs. Am I blind?

Thanks in advance!

Rossko

unread,
Jun 7, 2010, 11:39:28 AM6/7/10
to Google Maps JavaScript API v3
> I'm wondering if there is a way to get 'heading' information from a
> street address.

I'm not sure exactly what you mean ; places don't have headings or
other intrinsic directional information.

Guessing this is what you want -
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/e8cb5a8c98767745/c6f35cc931078f5d
where the heading is from the view to the given point.

Chad Killingsworth

unread,
Jun 7, 2010, 11:39:43 AM6/7/10
to Google Maps JavaScript API v3
You can calculate the heading (bearing) between 2 lat lng points. I
find this page helpful: http://www.movable-type.co.uk/scripts/latlong.html

Here's my JavaScript translation:

/**
* @param {google.maps.LatLng} newLatLng
* @returns {number}
*/
google.maps.LatLng.prototype.bearingTo = function (newLatLng) {
var lat1 = this.lat() * Math.PI / 180.0;
var lat2 = newLatLng.lat() * Math.PI / 180.0;
var lngDiff = (newLatLng.lng() - this.lng()) * Math.PI / 180.0;
var y = Math.sin(lngDiff) * Math.cos(lat2);
var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) *
Math.cos(lat2) * Math.cos(lngDiff);
return ((Math.atan2(y, x) * 180 / Math.PI) + 360) % 360;
}

Chad Killingsworth

geoco...@gmail.com

unread,
Jun 7, 2010, 11:52:26 AM6/7/10
to Google Maps JavaScript API v3
It isn't too hard to calculate the bearing from the streetview camera
location to the geographic location of a building. The issue is that
it only works when the geocoder returns a "rooftop" geocode for the
address. Are you doing this in an area where rooftop geocodes are
available?

I have an example using v2, I haven't looked at streetview in v3 yet.
http://www.geocodezip.com/example_geo_streetview.asp

-- Larry

>
> Thanks in advance!

volksman

unread,
Jun 7, 2010, 8:38:40 PM6/7/10
to Google Maps JavaScript API v3
I don't see any reference to 'rooftop' in my response. Here is a
typical example of a geocoding response for an address in my area:

http://maps.google.com/maps/geo?q=559+redwood+st+ottawa+on&key=

{
"name": "559 redwood st ottawa on",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "559 Redwood Ave, Ottawa, ON K2A 3E7, Canada",
"AddressDetails": {
"Accuracy" : 8,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "ON",
"SubAdministrativeArea" : {
"Locality" : {
"LocalityName" : "Ottawa",
"PostalCode" : {
"PostalCodeNumber" : "K2A 3E7"
},
"Thoroughfare" : {
"ThoroughfareName" : "559 Redwood Ave"
}
},
"SubAdministrativeAreaName" : "Ottawa Division"
}
},
"CountryName" : "Canada",
"CountryNameCode" : "CA"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 45.3844565,
"south": 45.3781612,
"east": -75.7659381,
"west": -75.7722333
}
},
"Point": {
"coordinates": [ -75.7690767, 45.3813114, 0 ]
}
} ]
}

Does that mean it's not available to me?

Thanks for all the info so far!



On Jun 7, 11:52 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> I have an example using v2, I haven't looked at streetview in v3 yet.http://www.geocodezip.com/example_geo_streetview.asp

geoco...@gmail.com

unread,
Jun 7, 2010, 10:40:10 PM6/7/10
to Google Maps JavaScript API v3
That point is on the street:
http://www.geocodezip.com/example_geo2.asp?addr1=(45.3813114,-75.7690767)&geocode=1&zoom=19&type=hybrid

> Does that mean it's not available to me?

Which means probably not yet.
This is what a "rooftop" geocode looks like:
http://www.geocodezip.com/example_geo2.asp?addr1=400%20Union%20Ave,%20Bridgewater,%20NJ%2008807,%20USA%20&geocode=1&zoom=18&type=hybrid

It is not on the road, it is on the building. Geocoders used to
always interpolate addresses along roads. Google introduced "rooftop"
goecodes in 2008:
http://googlemapsapi.blogspot.com/2008/05/shout-it-from-rooftops.html

-- Larry

>
> Thanks for all the info so far!
>
> On Jun 7, 11:52 am, "geocode...@gmail.com" <geocode...@gmail.com>
> wrote:
>
>
>
> > On Jun 7, 8:17 am, volksman <webri...@gmail.com> wrote:
>
> > > Hello All!
>
> > > I'm wondering if there is a way to get 'heading' information from a
> > > street address.  My maps feature specific street addresses and I'm
> > > creating a custom control to allow people to see the address at street
> > > level.  But right now when they hit the control it just drops them in
> > > a street view but heading north.
>
> > > I get my Lat/Long from the geocoding service.  Was wondering if there
> > > is a way to get heading info from that service too.
>
> > > I don't see any mention of it in the docs.  Am I blind?
>
> > It isn't too hard to calculate the bearing from the streetview camera
> > location to the geographic location of a building.  The issue is that
> > it only works when the geocoder returns a "rooftop" geocode for the
> > address.  Are you doing this in an area where rooftop geocodes are
> > available?
>
> > I have an example using v2, I haven't looked at streetview in v3 yet.http://www.geocodezip.com/example_geo_streetview.asp
>
> >   -- Larry
>
> > > Thanks in advance!- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages