google-panorama-by-id

gets a Google Street View by pano id

Usage no npm install needed!

<script type="module">
  import googlePanoramaById from 'https://cdn.skypack.dev/google-panorama-by-id';
</script>

README

google-panorama-by-id

experimental

Gets a Google Street View by pano ID. Also features some Node support.

var panorama = require('google-panorama-by-id')

var id = 'dXZfBMex9_L7jO2JW3FTdA'
panorama(id, function (err, result) {
  if (err) throw err
  
  // pano ID
  console.log(result.id)

  // actual latitude, longitude
  console.log(result.latitude)
  console.log(result.longitude)

  // other details from Google API
  console.log(result.copyright)
})

In Node, the request uses an undocumented API entry-point, using request. It only provides { id, latitude, longitude }. This is mostly useful for unit testing.

Usage

NPM

panorama(id, [opt], cb)

Gets the panorama data at the given id, a pano_id string like "dXZfBMex9_L7jO2JW3FTdA". The opt object is optional, and can contain:

  • service - (browser only) the Google API StreetViewService to use, defaults to a new instance

The Node-style callback uses the form (err, result), where err will be null if a street view was found. On success, result is an object containing:

{
  id: String, // pano ID
  latitude: Number,
  longitude: Number
}

In the browser, the result object will also contain other details from StreetViewService, like copyright and location.

node

The node.js entry point uses request to request the JSON. However, it also works in the browser, using jsonp. This means you can require it for quick unit testing in Node/browser, without bringing in the entire Google Client library.

var panorama = require('google-panorama-by-id/node')

panorama(id, callback)

However, this is not recommended for production, since it uses an undocumented API entry point and only returns a limited set of data.

See Also

License

MIT, see LICENSE.md for details.