How to Change the position of the instruments of Street View - google-maps

I am using Google Maps API V3, I would like to know how I can change the position of the elements (shown in picture http://www.pikky.net/uploads/d6964cfad0bb97cc3ada7852df260a715234d69a.png) when the user is INSIDE Street View.
Thanks,
Mirko

You achieve this by defining your StreetViewPanoramaOptions to a StreetViewPanorama object that you will initialize to your map variable when declaring the map options. It's in the StreetViewPanoramaOptions that you can determine the positions of the controls for when you're in the street view. (Refer to this document for more info https://developers.google.com/maps/documentation/javascript/reference#StreetViewPanoramaOptions ). Here is a snippet on how to approach this. (Note: this should all be done in your initialize() function prior to initializing your map variable).
First we will declare a variable for StreetViewPanoramaOptions and change options as we desire:
var panoramaOptions = {
addressControlOptions : { position : google.maps.ControlPosition.BOTTOM_CENTER },
zoomControlOptions : { position : google.maps.ControlPosition.TOP_RIGHT},
enableCloseButton : true,
visible: false //set to false so streetview is not triggered on the initial map load
};
The next step is to declare a StreetViewPanorama object that is set to the container/div of the map with the StreetViewPanoramaOptions from above:
var panorama = new google.maps.StreetViewPanorama(document.getElementById("map_canvas"), panoramaOptions);
Lastly, we declare the map options and set the map variable with the map options like we would normally do. Except, in the map options we set the streetView option to the panorama variable:
var mapOptions = {
center: new google.maps.LatLng(42.345573,-71.098326),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetView : panorama //this is where we set the panorama object to the map
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
Refer to this source for how to position controls in the map div ( https://developers.google.com/maps/documentation/javascript/controls#ControlPositioning )

Related

getting an image of current google map

Does anyone know how can i get the static image of my currently displayed google map. I have used this code to get the googl map in a div
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(0,0),
zoom:1,
scrollwheel:false,
disableDefaultUI: true,
draggable: false
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
I amm using thise url to get the static image
http://maps.googleapis.com/maps/api/staticmap?center=0,0&zoom=1&size=750x425&sensor=false&visual_refresh=true&scale=1
However i am not getting the image same as the one displayed by the function.
The maximum allowed width/height without a business-license is 640px
What you can do: use a scale of 2, set the zoom to 0 and for width/height use the half size:
http://maps.googleapis.com/maps/api/staticmap?center=0,0&zoom=0&size=350x212&sensor=false&visual_refresh=true&scale=2
Note: the result will not be exactly the same, because the zoom is different. You'll see different labels(at zoom 0 e.g. you'll see no labels)

Google map in a tab created with angularjs is not centered

I have the following problem:
I'm working in an aplication to book hotels that has tabs ("Hotel Details", "Map", "Reviews") in the overview page. the tabs are created with angularjs.
also, in the page I have the hotel address that is a link to the "Map" tab.
When I click on the "Map" tab, the google map is rendering ok. But, when I click on the hotel address, the "Map" tab opens but the map is not centered. If I refresh the page, it appears centered.
this is the code that process the map:
$scope.loadMap = function (targetID){
var latitude = $scope.latitude;
var longitude = $scope.longitude;
if(latitude && longitude && document.getElementById(targetID) != null ){
var center = new google.maps.LatLng(latitude, longitude);
var map_options = {
zoom: 13,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// create map
var map = new google.maps.Map(document.getElementById(targetID), map_options);
// configure marker
var marker_options = {
map: map,
position: center,
title: $scope.hotelName
};
// create marker
var marker = new google.maps.Marker(marker_options);
var infoWindow = new google.maps.InfoWindow();
window.setTimeout(function(){
google.maps.event.trigger(map, 'resize');
},2000);
}
}
Can you help me, please?
I've had this very problem when I was creating maps using Leaflet.js. I was trying to initialize the map inside of my angular service and it was loading very strangely. It appears you are trying to do the same thing, but you're doing it inside of your controller, rather than a service, but the effect is the same thing.
The problem is timing. Your controller is run before the DOM finishes loading and before angular has a chance to scan through the DOM to build out your Map page partial. Because of that, the page is only partially loaded when you call $scope.loadMap, which loads the google map, as you would expect. The problem is that once Angular finishes scanning the DOM partial, it modifies the DOM and then loads it into the view. When this happens, the google map has already been initialized to its default size based on the previous state of the DOM, and doesn't resize properly when angular is finished with the DOM.
Ok, that was a long explanation, but here's how you fix it:
You should do all of your map initialization inside of a directive's linking function. You could create a directive called something like app.directive('hotelMap'), which would initialize your map using the $scope.latitude and $scope.longitude variables from your controller.
link: function(scope, elem, attrs){
var center = new google.maps.LatLng(scope.latitude, scope.longitude);
var map_options = {
zoom: 13,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// create map
var map = new google.maps.Map(document.getElementById(targetID), map_options);
// configure marker
var marker_options = {
map: map,
position: center,
title: $scope.hotelName
};
// create marker
var marker = new google.maps.Marker(marker_options);
var infoWindow = new google.maps.InfoWindow();
}
And then in your map partial, you would have an element that looks something like <div hotel-map></div>. This fixes your problem, because your map will never be initialized until Angular has finished scanning/modifying the DOM and has finished rendering your partial. That way, the map's containing element will be at its final size/position and the map will be loaded into the element's center properly. Give it a try and let me know if that works.

How to use google.maps.Size

While instantiating an object of google.maps.Map class, I want to set the width and height of the map.
var mapOptions = {
center: new google.maps.LatLng(122.5, 200),
mapTypeId:google.maps.MapTypeId.HYBRID;
zoom: 15,
scaleControl: false,
};
this.map.mapObject = new google.maps.Map(document.getElementById("google_map"), mapOptions);
I'm using above code to create instance of Google map but I dont know how to use google.maps.Size class.
Could anyone please explain how to use google.maps.Size class ?
There is no size property in the MapOptions object. You have to make sure your HTML element ("google_map") has a valid size when the map is created or trigger the "resize" event on the map object once it has a valid size.

Google Maps javascript API- Map object recenters after applying KML layer. How do I prevent this?

Google Maps javascript API question - Map object recenters after applying KML layer. How do I prevent this?
I created a simple page with a map. When I apply a simple polygon KML, it recenters and zooms the map. Any ideas?
var myOptions = {
center: new google.maps.LatLng(27, -97),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var buildings = new google.maps.KmlLayer('https://mysite/site/buildings.xml');
buildings.setMap(map);
//i tried this to recenter and zoom, but no dice.
var posn = new google.maps.LatLng(27, -97);
map.setCenter(posn);
map.setZoom(17);
Sounds like you need the preserveViewport option. From the documentation:
By default, the input map is centered and zoomed to the bounding box of the contents of the layer. If this option is set to true, the viewport is left unchanged, unless the map's center and zoom were never set.
Pass it a KMLLayerOptions object through the constructor:
var buildings = new google.maps.KmlLayer('https://mysite/site/buildings.xml',{preserveViewport:true});

Google Maps Api v3 - set map position in runtime

How can I change position of the map, from where it is pointing now, to ie. 45.00,19.00, but in a runtime, now when map is initialized?
my application have to "jump" from some coordinates to other, so that's why I need this ability.
ok, here it is:
MyMap.map.setCenter(new google.maps.LatLng( 45, 19 ) );
Create that Map object, save it to a variable (i.e. map) and then use map.panTo().
See the reference of Map
you need the extended MVCObject() ....
there you find getPosition() (return: LatLng) and setPosition(latlng:LatLng)
you just need to set this property and map location will change
Define the place where to position
Pass that to map.setCenter()
var map;
function initMap() {
var container = document.getElementById('map');
var options = {
zoom: 18,
gestureHandling: 'cooperative',
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(container, options);
var myPlace = { lat: 23.7266, lng: 90.4216 };
map.setCenter(myPlace);
}