I'm using the Google Maps Javascript API and I have LatLng coordinates that are dynamically generated. The problem is, sometimes I get coordinates and a zoom level that creates a map view that's 'off the chart' and this confuses users into thinking their map is not working. Is there a set of coordinates I should restrict values to in order to avoid this?
Example:
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(-89.16090481395844, 59.24382269379974),
zoom: 13,
mapTypeId: 'roadmap',
scaleControl: true,
navigationControlOptions: { style: google.maps.NavigationControlStyle.ZOOM_PAN }
});
Users don't know what's happening unless they zoom out:
Google Maps imagery stops at lat 85.0511 (-85.0511).
The value comes from features of spherical mercator projection that Google Maps is based on. You can find the formula used to calculate the value here: http://en.wikipedia.org/wiki/Mercator_projection#Uses
Related
I am working on a map project where I need clustering. I implemented a store locator and used MarkerClusterer which works fine. Now I have another requirement from the customer and I wonder which solution I should use to achieve these goals:
Zoom level 0: Cluster markers within 1500km distance to each other
Zoom level 1: Cluster within 1000km
Zoom level 2: Cluster within 750km
Zoom level 3: Cluster within 400km
Zoom level 4 and above: no clustering
I was thinking I should be using MarkerManager and MarkerClusterer together, but I am not sure about that. Any help to get me on the right path?
Thanks in advance!
You can only use MarkerClusterer, but you have to modify some options.
To prevent the clusterer acts after level 4, you have to use maxZoom property. It defines the max level where the clusterer can cluster marker, so in your case, you have to fix it at 4.
Then, to change the size of the grid depending the zoom level, use gridSize property. You can find a definition of all option fields on the doc.
So, your MarkerClusterer instanciation will look like something like this :
var mcOptions = {gridSize: /*Your value*/, maxZoom: 4};
var markerCluster = new MarkerClusterer(map, /*your array of markers*/ mcOptions);
I have a google map and I am using the drawing library to let the user draw polygons on the map by clicking to add points.
As a comparison I looked at trulia.com. I don't know how the drawing library setup is being made on trulia (uses backbone and other stuff). While I draw a shape, I want it to get filled as soon as I have 3 points, even if I am still drawing, and the fill should change as I add new points (indicating what the shape/area would be if you'd close it in that moment).
On trulia.com, as soon as you have a 3rd point, the area designated by the existing points gets filled, even though you haven't finished adding points. They're using google maps api, right? But I can't find the setting for something like "fill shape as you add points". I've searched google a lot, no luck.
Does anyone know how to setup the map or the drawing library to have that behavior? I don't think that this behavior can be setup in the polygonOptions (I've looked at all the options documented on developers.google.com)... so, the setting must be somewhere else...
MrCroft, it seems #ddtpoison777 asked a similar question and found the solution among some Google Maps API samples. This is the relevant code taken from the example:
var poly;
var path = new google.maps.MVCArray;
function initialize() {
poly = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
poly.setMap(map);
poly.setPaths(new google.maps.MVCArray([path]));
google.maps.event.addListener(map, 'click', addPoint);
}
function addPoint(event) {
path.insertAt(path.length, event.latLng);
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
marker.setTitle("#" + path.length);
}
I have loaded a KML file into a Google map using both V3 and geoxml3. The file contains one line, saved from Maps walking directions. I want to add mile markers to the line, but I can't find any documentation on how to get a polyline from the KmlLayer (or from the geoXML3 object).
V3:
var layer = new google.maps.KmlLayer('http://blah.kml');
layer.setMap(map);
geoXML3:
var kml_parser = new geoXML3.parser({
map: map,
processStyles: true,
createMarker: add_marker
});
kml_parser.parse('blah.kml');
Does anyone know
The first Polyline is accessible in geoxml3 by:
kml_parser.docs[0].gpolylines[0]
or as a property of the placemark
kml_parser.docs[0].placemarks[0].polyline
(the Polylines are not accessible in KmlLayer, they are rendered on tiles)
Example from a search of SO for [google-maps-api-3] geoxml3 polyline)
Another example:
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?type=k&filename=http://www.geocodezip.com/geoxml3_test/SO_IT_info_kmlC.xml
I'm using the google-maps-utility-library-v3 to incorporate a Google Earth API view to a Google Maps API v3 implementation. Those Google Maps API v3 / Earth API utilities have been written by user jlivni as far as I can tell, the availability of which code has helped me greatly thus far.
(very rough working prototype of my implementation is here)
The problem I have is that I want to default (on page load) to the Google Earth view, rather than (as in the prototype above) one of the Maps API v3 standard views.
I have looked at lines 81, 131 and 133 of the (uncompiled?) googleearth.js at the above link (under src) and tried the following when setting the Maps API options within my JourneyImmersionInitialiseMapLoadGPXAnimate.js ...
var myOptions = {
zoom: 18,
center: arr_lat_lon[currentTrk][currentTrkseg][0],
scaleControl: true,
tilt: 45,
mapTypeId: earthMapType,
overviewMapControl: true,
overviewMapControlOptions: {
opened: true
}
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
... but get ...
ReferenceError: earthMapType is not defined
Additionally I've tried ...
mapTypeId: GoogleEarth.earthMapType,
... which results in a grey map canvas with no map type options on the top right. Once I've selected the Earth view from the page I can then change between the standard Earth API map types at the console in Firebug using ...
earth.getInstance().getOptions().setMapType(earth.getInstance().MAP_TYPE_EARTH)
... or ...
earth.getInstance().getOptions().setMapType(earth.getInstance().MAP_TYPE_SKY)
... but again, use of earthMapType or GoogleEarth.earthMapType in place of the last element results in an error at the Firebug console, this time ...
Error: Error calling method on NPObject!
Any help would be greatly appreciated.
Thanks in advance
(as I'm a newbie I can't provide more than two links in this post but wanted to add that I have looked at stackoverflow.com/questions/3039250/google-earth-integrated-with-google-maps-api-v3)
This library doesn't have a public method to switch programmatically, and if you try to do it before all the setup is in place, it will fail. Ideally there would be a callback after instantiating your GoogleEarth object, but lacking that you can hack around the issue by using the private showEarth_() method on the uncompiled JS.
Noting you have to wait an arbitrary amount of time before the plugin is ready, something like this should generally do the trick:
googleEarth = new GoogleEarth(map);
setTimeout('googleEarth.showEarth_();',1000);
This is all pretty hackish, so please file a feature request on the issue tracker to add in a supported method for switching to the Earth type programmatically.
I am a newbie in google map. I learn from google map documentation but I don’t found anything about postal code to google map. I only have a postal code to get the google map. If so can I get a map from postal code.
I also find in google for tutorials for that but I don't found anything. If you have a useful code or tutorial, please help me.
You first need to get the latitude/longitude from address/postcode. There is a Google GeoCodeing API for getting longitude and lattitude from address and possibly post code. It got some usage limits though. Have a look
http://code.google.com/apis/maps/documentation/geocoding/
Once u get the long/lat u can then feed these into google mapping api
E.g. Using the following javascript api
http://maps.google.com/maps/api/js?sensor=false
You can do
RenderMap(54.1109429427243, -3.197265625, 6, "resultsMapHome");
function RenderMap(lat, lng, zoomLevel, divName) {
var position = new google.maps.LatLng(lat, lng);
var options = {
zoom: zoomLevel,
center: position,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(divName), options);
map.setCenter(position);
}
I can't format the script as I am typing from my iPhone. I will reformat it later when I get to work.
http://maps.google.com
Put in the post code, zoom in / out until you have the position you'd like the map on your own website. Then click the 'link' button to the right of the search bar (looks like a chain). This gives you the appropriate code to put that map into your website.
Is that what you wanted? I couldn't understand your English very well.