Skip to content

Instantly share code, notes, and snippets.

@mishudark
Created May 28, 2013 05:21
Show Gist options
  • Save mishudark/24daf7540aab610543d2 to your computer and use it in GitHub Desktop.
Save mishudark/24daf7540aab610543d2 to your computer and use it in GitHub Desktop.
var streetview = {
//overwrite with tag id
tag_container: 'map-street',
sv: null,
panorama: null,
init: function(){
this.sv = new google.maps.StreetViewService();
this.panorama = new google.maps.StreetViewPanorama(document.getElementById(this.tag_container));
},
//set position from LatLng google maps object
setPosition: function(LatLng){
this.panorama.setPosition(LatLng);
},
//get and show position from address
setPositionFromAddress: function(address){
var geocoder = new google.maps.Geocoder()
//replace spaces to +
var matcher = /\%20/gi;
adress = address.replace(matcher, "+");
matcher = /\s/gi;
adress = address.replace(matcher, "+");
geocoder.geocode({ 'address': address}, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
streetview.setPosition(results[0].geometry.location);
}else{
console.log("Geocode was not successful for the following reason: " + status);
}
});
}
}
//usage
streetview.init();
//var latlng = new google.maps.LatLng(37.869085,-122.254775);
//streetview.setPosition(latlng);
//or
streetview.setPositionFromAddress('centro,pachuca hidalgo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment