Reputation: 135
I am currently using the Google Maps JavaScript API like that:
function initMap() {
var locationRio = {lat: -22.915, lng: -43.197};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 18,
center: locationRio
});
var marker = new google.maps.Marker({
position: locationRio,
map: map,
title: 'Hello World!'
});
}
This will create a map of Rio de Janeiro
- but I want it to randomly drag/pan the map (a bit, not a lot)
I've tried adding more float numbers next to the latitude and the longitude (for example: {lat: -22.9159504, lng: -43.1978506}
) but it doesn't make a medium difference (I want it not so big and not so small difference)
Upvotes: 0
Views: 36
Reputation: 133400
You coul try using random
function initMap() {
var random = Math.random( );
var lat = -22.915;
var lng = -43.197;
var locationRio = {lat: (lat + random/100), lng: (lng +random/100)};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 18,
center: locationRio
});
var marker = new google.maps.Marker({
position: locationRio,
map: map,
title: 'Hello World!'
});
}
Upvotes: 1