I am having problems using the MarkerManager. Somehow Markers added with the MarkerManager do not show up, though i do mgr.refresh(); It works when i use basic map.addOverlay(marker); but not when using mgr.addMarker(marker);. Weird. Hope someone here can help.
Here's the relevant code:
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
bounds = new GLatLngBounds();
map.setCenter(new GLatLng(48.25, 11.00), 4);
mgr = new MarkerManager(map, mgr_options);
markers = createSpotMarkers(spots); // parsing spots, extending bounds, creating Array of GMarkers etc, pretty basic and seems not be relevant.
mgr.addMarkers(markers); // does not work
map.addOverlay(markers[0]); // works
mgr.addMarker(markers[0]); // does not work either
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)-1);
mgr.refresh();
}
It looks like the API for MarkerManager expects 3 arguments to addMarkers, of which the 3rd seems to be optional. The second, however, doesn't. If the API doesn't help, then a blog post showing example usage might. Good luck!
Related
I wanna add Multiple Marker to esri map by using flex 4.6 on flash builder platform
`
private function addSomeMarkers(x:Number,y:Number):void
{
// This is just to show how to add markers
// using ActionScript code as opposed to MXML tags.
//(lat, lon, new SpatialReference(102697));
// outSR:SpatialReference = new SpatialReference(4326);
//GCS_WGS_1984
var myGraphicMarker:Graphic = new Graphic(new MapPoint(y,x, new SpatialReference(102100)),
new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 14, 0x009933));
myGraphicMarker.toolTip = "Marker added with ActionScript";
myGraphicsLayer.add(myGraphicMarker);
myGraphicMarker=null;
}`
These is my current function recives an (x,y) from dataBase but when i run program it just add only one the first recived x,y .
I checked my my code and im sure the function recives multiple point x,y....
Please help me and thank you>>>>>>>>>>>>>>>>>>>>>>>>>>>
I am working on same type of program and its working fine for me. May be you can try with some hard-coded values for Map points first. As I can see you are interchanging the positions of "y" and "X" in the map point.
var myGraphicMarker:Graphic = new Graphic(new MapPoint(y,x, new SpatialReference(102100)),
new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 14, 0x009933));
I need to highlight a section of a street between two intersections. I have found a similar question which was asked more than a year ago (see here) which says that Google, Bing, etc. do not provide street data through their APIs. Does anyone know if anything has changed in the APIs, and whether I can get street location latitude/longitude data from somewhere now?
I have done this in API V2, but it should not be to difficult to rewrite it for V3.
Have a look at this website http://www.fvs.de/anfahrt.php (in German) and click the "Weg in Karte zeigen" buttons ("show way in map") in the sections below the map. Each button highlights another street line in the map.
It is basically done by using directions object of Google Maps to plot a route between two arbitrary street points in the map (e.g. your two intersections). The points must be encoded with their LatLng coordinates. Here is a code example (as said this is API V2):
function initMap() { // called by page onload event
if (GBrowserIsCompatible()) {
// Display the map, with some controls and set the initial location
gMap = new GMap2(document.getElementById("map_canvas"));
gMap.addControl(new GLargeMapControl());
// ...
gMap.setCenter(GLatLng(49.238326, 6.977761), 15);
// init directions object and attach listener to handle route loads from function highliteRoute()
gDir = new GDirections();
gPoly = null;
GEvent.addListener(gDir, 'load', function(){
gPoly = gDir.getPolyline();
gMap.addOverlay(gPoly);
// zoom & pan to poly
var polyBds = gPoly.getBounds();
var polyZoom = gMap.getBoundsZoomLevel(polyBds);
gMap.setZoom(polyZoom);
gMap.panTo(polyBds.getCenter());
});
}
}
function highliteRoute(){
if(gPoly!=null) gPoly.hide();
gDir.load('from: 49.313530,6.969109 to: 49.238326,6.977761', {getPolyline:true});
}
I researched the Maps Api and it's pretty complicated for me..and I didn't find what I want.
I wrote a php program that does some gps coordinate manipulation and returns me 2 sets of latitude and longitude value ready to use. All I want is to generate a map showing 2 markers for these 2 places, with a straight line between them.
One pair of LAT/LNG value is different each time but for sure somewhere in US, and the other pair is random, can be anywhere in the world. (and hence, maybe the zoom level should adjust accordingly)
How should I implement this? Thanks a lot!
edit:
I have created this map with 2 markers, code:
echo '
function initialize() {
var pos_query = new google.maps.LatLng('.$decimal_latitude.','.$decimal_longitude.');
var pos_tim = new google.maps.LatLng('.$result_tim_lat.','.$result_tim_lon.');
// var latlngbounds = new GLatLngBounds();
// latlngbounds.extend(pos_query);
// latlngbounds.extend(pos_tim);
var myOptions = {
zoom: 5,
center: pos_tim,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false
};
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
//---> map.setCenter(latlngbounds.getCenter(), map.getBoundsZoomLevel(latlngbounds));
var marker_query = new google.maps.Marker({
position: pos_query,
map: map,
title:"Your query location"});
var marker_tim = new google.maps.Marker({
position: pos_tim,
map: map,
title:"Tim Horton"});
}
</script>';
However, I want to auto-adjust the zoom level and center of map using the code in comment.
But it doesnt work (the map doesnt show up)
I guess Im using V3 and the code in the comment part is older version?
Most of the Maps API's will do what your asking easily. You should read this Google Maps API-Jscript
This will get you started.
This is the actual API reference and is where you will find Maps, Controls, Overlays and Services. Pay special attention to the Overlays section, this is what you need to place your points on a map as well as custom images or graphics. The rest is programming. If you have specific questions regrading programming your best bet is to try some of this in your code and come back with code examples of what you're trying. Hope this helps.
I've just begun using the Google Maps API (v3.0) and have had a good deal of success so far. I am loading a set of objects with Latitude & Longitude values from a database, passing them into my script, and looping over them in the script in order to add them to the map.
I am using the "bounds.extend() / map.fitBounds()" method of setting the map's zoom & bounds (see code below), which works as expected the first time around; however, if I clear out the existing markers, fetch another set of objects, and do the same thing on the same map instance, it sets the bounds incorrectly, usually resulting in a minimum zoom (an astronaut's view).
My suspicion is that my map object has some memory of the previous set of bounds that I've given it and that I need to find a way to clear these bounds before assigning my new ones, but I really can't be too sure.
Any help is greatly appreciated!
var locationList = [];
for (var i = 0; i < mapPoints.length; i++) { // mapPoints is a collection of DTOs
var mapPoint = mapPoints[i];
var location = new google.maps.LatLng(mapPoint.Latitude, mapPoint.Longitude);
locationList.push(location);
var marker = new google.maps.Marker({
map: map,
icon: '/Content/images/map/' + mapPoint.Status.Icon,
shadow: '/Content/images/map/shadow.png',
position: location
});
markers.push(marker); // markers is an Array that is managed outside this loop
}
var bounds = new google.maps.LatLngBounds();
for (var j = 0; j < locationList.length; j++)
bounds.extend(locationList[j]);
map.fitBounds(bounds);
This isn't the answer, so to speak, but a (slightly hacky) workaround that I discovered on a thread in the Google Maps Javascript API v3 group:
//map.fitBounds(bounds);
setTimeout( function() { map.fitBounds( bounds ); }, 1 );
if the above answer doesn't work for you (it didn't for me), the problem might lie in bootstrap (assuming you're using it). bootstrap modals specifically generate all sorts of wonky behaviour when i embed a map object in it.. curiously correcting itself if/when i drop an 'alert' in there.. in any case, i solved all my problems by just building my own modal (ie, not using bootstraps modals).
I want to have draggable markers (already done), but I need to be able to turn off draggability in certain conditions.
Marker is created like this;
var Marker = new GMarker(center,{draggable:true});
...which works fine. But I can't figure out how to make it undraggable.
like this
var myMarker = new GMarker(center,{draggable:true});
myMarker.disableDragging();
http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GMarker.disableDragging