I am trying to implement this example on my webforms page, slightly different. I have a map and when I change its mode to streetview, I want to show a small map on its bottom left corner that follows the streetview. The image I think is clear of what I try to achieve.
When the map is initialised I do the following
var mapOptions = {
center: new google.maps.LatLng(latitude, longitude),
zoom: 10,
tilt: 30,
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
streetViewControl: true,
streetViewControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
}
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
var smallmapOptions = {
center: new google.maps.LatLng(latitude, longitude),
zoom: 15
};
smallmap = new google.maps.Map(document.getElementById("smallmap"), smallmapOptions);
and when the pegman is dropped I set the streetview to the little map as following
google.maps.event.addListener(map.getStreetView(), 'visible_changed', function () {
if (this.getVisible()) {
$("#smallmap").show();
var streetViewPanorama = new google.maps.StreetViewPanorama(document.getElementById("map"), {
position: new google.maps.LatLng(latitude, longitude),
pov: {
heading: 34,
pitch: 10
}
});
smallmap.setStreetView(streetViewPanorama);
} else {
$("#smallmap").hide();
}
});
however I do not get the desired result as you see in this pic. My setup or way of doing this must be wrong.
edit: I also tried the following, but no difference
var streetViewPanorama = new google.maps.StreetViewPanorama(document.getElementById("map"), {
position: new google.maps.LatLng(this.position.lat(), this.position.lng()),
pov: {
heading: 34,
pitch: 10
}
});
by the way, I do not understand this pov property of the above, maybe this is causing the issue?
I changed the smallmapOptions code to the following and moved it inside the visible_changed event and now I see the small map clearly with the pegman walking according to the map's streetview
var smallmapOptions = {
center: new google.maps.LatLng(this.position.lat(), this.position.lng()),
zoom: 15
};
smallmap = new google.maps.Map(document.getElementById("smallmap"), smallmapOptions);
Related
We are currently using two google maps on one page, the first one is an aerial view, and this I can turn off draggable and it works fine. The other is an internal view of the building, when I use the same code on this, it doesnt disable draggable on mobile or on desktop, I can disable scrollwheel movement, but not draggable. The code I am using is below.
function initialize2() {
var fenway = new google.maps.LatLng(0, 0);
var mapOptions = {
center: fenway,
scrollwheel: false,
zoom: 8,
draggable: false
};
var panoramaOptions = {
position: fenway,
scrollwheel: false,
draggable: false,
<?php echo(isMobile()) ? 'draggable: false,' : ''; ?>
pov: {
heading: 180,
pitch: 0
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById('map-canvas2'),panoramaOptions);
map.setStreetView(panorama);
}
google.maps.event.addDomListener(window, 'load', initialize);
You just need to add: draggable: false like this
// Function to initialize the map within the map div
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 27.963989, lng: -82.799957},
zoom: 14,
draggable: false
});
}
I have two Google Maps setups on a site that I'm developing, and I want to apply custom markers to both of them. This is what I have written -
var coordinates_1 = new google.maps.LatLng(x, x);
var coordinates_2 = new google.maps.LatLng(x, x);
var map_1_options = {
zoom: 14,
center: coordinates_1,
mapTypeControl: false,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map_2_options = {
zoom: 14,
center: coordinates_2,
mapTypeControl: false,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var marker_1 = new google.maps.Marker({
position: coordinates_1,
map: map_1,
icon: '/images/marker.png'
});
var marker_2 = new google.maps.Marker({
position: coordinates_2,
map: map_2,
icon: '/images/marker.png'
});
var map_1 = new google.maps.Map(document.getElementById('location_1'), map_1_options);
var map_2 = new google.maps.Map(document.getElementById('location_2'), map_2_options);
I guess the script can be optimised but that's not the important issue here. What happens is I don't get any error messages (or missing images), and I get both maps displayed at their right location but no markers are showing. The images are 32x32px if that matters.
Any help would be appreciated.
You must first create map_1 and map_2 before you use them as map-property for the markers.
How can I hide map types bar on Google Maps?
(hide Ter, and Earth on menu bar)
I create code from http://maps.google.com
I suggest you to look at this:
http://code.google.com/apis/maps/documentation/javascript/controls.html
Short:
mapTypeControl: false
this will hide map types bar.
or here is init function:
function initialize() {
var myOptions = {
zoom: 4,
center: new google.maps.LatLng(-33, 151),
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
Vahagn's answer will completely hide the bar. But it's not clear from your question if this is what you want to do, or if you only want to hide just the options for Terrain and Earth. If the latter, you could try:
function initialize() {
var myOptions = {
zoom: 4,
center: new google.maps.LatLng(-33, 151),
mapTypeControlOptions: {
mapTypeIds: [
google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.SATELLITE
]
},
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
Basically you need to set the property mapTypeControl to false like this:
mapTypeControl: true,
here is a live example of a page that offers customization with respect to look and feel.
I'm trying to make a street panorama of a given location on a map. Sometimes the panorama works fine with the location as the position of the panorama, and other times it shows only a gray screen with controls. To solve this, I am trying to use the StreetViewService.getPanoramaByLocation(). The returned LatLng from this function is VERY close to the LatLng's of the locations of panoramas that already work, but the panorama is ALWAYS gray when I use this input as position. I've done lots of research and still cannot solve the problem.
Here is my code:
function init() {
var location = new google.maps.LatLng(<%=id%>);
map = new google.maps.Map(document.getElementById("map_canvas"), {
center: location,
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
marker = new google.maps.Marker({
map: map,
position: location
});
var client = new google.maps.StreetViewService();
client.getPanoramaByLocation(location, 49, function(result, status) {
if (status == "OK" )
location = result.location.latLng;
});
myPano = new google.maps.StreetViewPanorama(document.getElementById("pano"), {
position: location,
pov: {
pitch: -10,
heading: 0,
zoom: 1
}
});
}
Any help would be greatly appreciated! Thanks!
I do this slightly differently from you. I only create the StreetViewPanorama if the status is 'ok'
var sv = new google.maps.StreetViewService();
sv.getPanoramaByLocation(streetViewLocation, 50, function(data, status) {
if (status == 'OK') {
//google has a streetview image for this location, so attach it to the streetview div
var panoramaOptions = {
pano: data.location.pano,
addressControl: false,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById(strMapCanvasID), panoramaOptions);
}
else{
//no google streetview image for this location, so hide the streetview div
$('#' + strMapCanvasID).parent().hide();
}
});
I have a map in which I apply a custom overlay using KMbox overlay to signify where I think the users general point of interest lies. What I want is to display this map to the user and allow them to click on the map to give me an exact location match of their POI.
This all works fine except for when the user clicks on the map and changes the zoom of the map.
Here's my code to add the marker to the map.
function addMarker(location) {
if(KmOverlay)
{
KmOverlay.remove();
}
if(last_marker)
{
last_marker.setMap(null);
}
marker = new google.maps.Marker({
position: location,
map: map
});
// Keep track for future unsetting...
last_marker = marker;
}
And to show the map I have this function.
function show_map(lt, ln, zoom, controls, marker)
{
var ltln = new google.maps.LatLng(lt, ln);
var vars = {
zoom: zoom,
center: ltln,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: controls,
navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN} ,
mapTypeControl: false,
scaleControl: false,
scrollwheel: false
};
map = new google.maps.Map(document.getElementById("map_canvas"), vars);
KmOverlay = new KmBox(map, new google.maps.LatLng(lat, lon), KmOpts);
var totalBounds = new google.maps.LatLngBounds();
totalBounds.union(KmOverlay.getBounds());
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng);
});
}
I have a working example at the following link here
fixed this by using the setMap() method on the KmOverlay and passing null as a parameter.
eg:
function addMarker(location) {
if(KmOverlay)
{
KmOverlay.setMap(null);
}