forked from Experience-Monks/google-panorama-by-id
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.js
28 lines (23 loc) · 788 Bytes
/
node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var request = require('./lib/request')
module.exports = function panoramaById (id, opt, cb) {
if (!id || typeof id !== 'string') {
throw new TypeError('must provide pano id')
}
if (typeof opt === 'function') {
cb = opt
opt = {}
}
opt = opt || {}
var url = 'http://maps.google.com/cbk?output=json&cb_client=apiv3&v=4&dm=1&pm=1&ph=1&hl=en&panoid=' + id
// in the browser we need to use jsonp to get the data
request(url, function (err, body) {
if (err) return cb(err)
if (!body || !body.Data) {
return cb(new Error('could not find street view by id: ' + id))
}
body.id = body.Location.panoId
body.latitude = parseFloat(String(body.Location.lat))
body.longitude = parseFloat(String(body.Location.lng))
cb(null, body)
})
}