问题
Something seems to have changed on google maps recently that changed the default zoom. I've tried adding zoom=17 and z=17, but nothing seems to change.
I'm just creating a hyperlink on page using the following url & query
"https://maps.google.com/?zoom=17&q=" +myAddress.replace(/ /g, '+');
In the past it's always worked fine no matter what address I used in the query. Just wondering what may have changed and if I need to work around this another way.
回答1:
Google maps, now, will not zoom past z=13 unless Latitude and Longitude are also supplied. EG: &ll=98.414257,-21.727585.
As a scripter, this makes your task a bit more involved; here is a pseudocode approach that will work:
Open the map page as before, but flag it (custom URL param or
GM_setValue) as first opened by your script.Set the script to also run on Google maps pages.
On flagged Google maps pages:
- Grab the share link.
- Change the
zparameter only, EG&z=17. - Make sure any flag is cleared.
location.replace()to the modified share link
Alternatively, a more durable strategy is to switch to using the Google Maps API.
回答2:
If you access Google Maps and click and share link button you will see something like this:
https://maps.google.com/?ll=53.944771,-0.854187&spn=0.890705,2.694397&t=m&z=9
So i think you should worry about some required field...
回答3:
Here's what I ended up using to solve the problem. I can specify zoom by z=16 provided latitude and longitude as Brock explained.
addMapLL('900+w+900+s+clearfield+UT'); // just a random address formatted
function addMapLL(address) {
var api = "https://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=" + address;
GM_xmlhttpRequest(
{
method: 'GET',
url: api,
onload: function(resp) {
var obj = JSON.parse(resp.responseText);
if (obj.status == "OK") {
var lat = obj.results[0].geometry.location.lat;
var lng = obj.results[0].geometry.location.lng;
var ll = "&ll=" + lat + "," + lng;
// .href is already set as follows
// https://maps.google.com/?z=16&q=900+w+900+s+clearfield+UT
document.getElementById('googlemap').href += ll;
}
}
});
}
来源:https://stackoverflow.com/questions/15842315/google-maps-link-from-greasemonkey-default-zoom