﻿
//to use this function, you need a StreetViewResult function
function getGStreetviewLocation(glatlng) {
    var gStreetviewClient = new GStreetviewClient();
    gStreetviewClient.getNearestPanorama(glatlng, function(gStreetviewData) {
        var gStreetviewLocation = new Object();

        if (gStreetviewData.code == 200) {
            //success - assign google result
            gStreetviewLocation = gStreetviewData.location;
            //determine bearing
            var yawDegree = bearing(gStreetviewLocation.latlng, glatlng);
            gStreetviewLocation.pov.yaw = yawDegree;
            gStreetviewLocation.pov.pitch = 0;
        }
        //assign requested latlng;
        gStreetviewLocation.requestedlatlng = glatlng;

        StreetViewResult(gStreetviewLocation);
    });
}

function createStreetView(domObjectId, lat, lng, yaw, pitch) {

    var domObject = document.getElementById(domObjectId);
    var gStreetviewPanorama = new GStreetviewPanorama(domObject);
    var latlng = new GLatLng(lat, lng);
    var pOV = { yaw: yaw, pitch: pitch };
    gStreetviewPanorama.setLocationAndPOV(latlng, pOV);
}

function generateStreetViewLink(domObjectId, gStreetviewLocation) {

    var lat = gStreetviewLocation.latlng.lat();
    var lng = gStreetviewLocation.latlng.lng();
    var yaw = gStreetviewLocation.pov.yaw;
    var pitch = gStreetviewLocation.pov.pitch;

    return "javascript:createStreetView('" + domObjectId + "', " + lat + ", " + lng + ", " + yaw + ", " + pitch + ")"
}
