Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsgoogle maps api help
am trying to display a map using one script as follows:?
var venue1Map,venue2Map;
function initialize() {
var pin1Location = new google.maps.LatLng(53.79666155483624,-1.5507932901382);
var pin2Location = new google.maps.LatLng(53.985939205000584,-1.51488971710209);
var mapOptions = {
zoom: 15,
center: pin1Location,
mapTypeId: google.maps.MapTypeId.ROADMAP,
panControl: false,
zoomControl: true,
zoomControlOptions: {
style: [google.maps.ZoomControlStyle.SMALL],
position: google.maps.ControlPosition.TOP_RIGHT
},
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
position: google.maps.ControlPosition.TOP_LEFT
},
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER
},
streetViewControl: false,
overviewMapControl: false,
}
venue1Map = new google.maps.Map(document.getElementById('map'), mapOptions);
venue2Map = new google.maps.Map(document.getElementById('map-2'), mapOptions);
var start1Position = new google.maps.Marker({
position: pin1Location,
animation: google.maps.Animation.BOUNCE,
map: venue1Map,
icon: "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcT2Fj0FjkkpWC1SQLvnPQ0EESWidU8p8tgn1PK5eTI1_Hw28wrzNw"
});
var start2Position = new google.maps.Marker({
position: pin2Location,
animation: google.maps.Animation.BOUNCE,
map: venue2Map,
icon: "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcT2Fj0FjkkpWC1SQLvnPQ0EESWidU8p8tgn1PK5eTI1_Hw28wrzNw"
});
start1Position.setAnimation(google.venue1Map.Animation.BOUNCE);
start2Position.setAnimation(google.venue1Map.Animation.BOUNCE);
}
function loadScript() {
var script = document.createElement('script');
script.src = 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;
But this seem to display the same map and with the same location for the two canvas. anything that l am doing wrong here guys? my end go is to use this script to display two maps each pointing at a different location.
1 Answer
Zack Klinger
17,622 PointsJust a guess, but in mapOptions you set center to pin1Location and you use that in both constructors.
You are also calling venue1Map for both start positions.
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 PointsKelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsthanks buddy that made me realise something else l did wrong and made it work.
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 PointsKelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsthanks buddy that made me realise something else l did wrong and made it work.