views:

377

answers:

4

Hi all,

In google maps when i set a center through

map.setCenter(new GLatLng(28.6589, 77.2104), 13);

it not only sets the centre of the map but adds a marker on that place which i dont want it to be

can anyone help me out?

with thanks Ankur

Ok guys I feel no harm to share my code at least it may help others also Here's the entire script I wrote

<script type="text/javascript">
    var map;
    function initialize() {
      if (GBrowserIsCompatible()) {


      map= new GMap2(document.getElementById("map_canvas"));


        map.setCenter(new GLatLng(28.6589, 77.2104), 13);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
       map.clearOverlays();
        //alert(PlottingMarkersDetails);
      }
      setInterval("plotVehicles()",1000);
    }
    function plotVehicles()
    {

     try
        {
            map.clearOverlays();
            var bounds = new GLatLngBounds();
            if(document.getElementById("<%=hf_SelectedVehiclePlottingDetails.ClientID %>"))
            {
            var PlottingMarkersDetails=document.getElementById("<%=hf_SelectedVehiclePlottingDetails.ClientID %>").value;

            var arrVehicleDetails=PlottingMarkersDetails.split("@");
            alert(arrVehicleDetails.length);
            for(var i=0; i<arrVehicleDetails.length;i++)
            {
                var currentVehicleInfo=arrVehicleDetails[i].split(",");

                var point = new GLatLng(parseFloat(currentVehicleInfo[1]),parseFloat(currentVehicleInfo[2]));
                var marker = createMarker(point,currentVehicleInfo[0] + "<br/>" + currentVehicleInfo[4] + "<br/>" + currentVehicleInfo[3] );
                //bounds.extend(point);
                map.addOverlay(marker);

            }
            //map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

            }
            }

        catch(err)
        {
        }

    }
    function createMarker(point,html) {
    var blueIcon = new GIcon(G_DEFAULT_ICON);
    blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";    
    markerOptions = { icon:blueIcon };            
        var marker = new GMarker(point,markerOptions);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }
    </script>
A: 

I just ran some sample code in the Google Playground and it doesn't add a marker when just using map.setCenter()

I ran the following:

function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
  }
}

UPDATE

From looking at the new code you just put up, the marker that you're concerned about must be getting added in your plotVehicles functionality. I would take a look at the vehicle data you're bringing back and see if there's something there.

Joseph
var map; function initialize() { if (GBrowserIsCompatible()) { map= new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(28.6589, 77.2104), 13); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.clearOverlays(); }}this is what i m using just try it with this code
Ankur
the clearoverlays is just added to clear that marker but doesnt work for me
Ankur
@Ankur - that code alone won't add a marker. I promise. :)
Chris B
@Ankur the code you posted there is working fine as well... there must be something else that you're not including.
Joseph
I have just edited and put the entire script please have a look on it
Ankur
+1  A: 

The setCenter method does not add a marker.

You're probably calling some other method as well which is adding a marker; please post all of the code.

SLaks
i have posted the entire code have a look
Ankur
+1  A: 

I suggest you debug your code. I only see one place where you're calling map.addOverlay() - add a breakpoint here and see if you ever call it, and if so, look at the call stack.

Pasting your entire application into a stackoverflow question is probably not the correct debugging technique :)

levik
A: 

It looks like your plotVehicles() function is adding the marker. Check the data which that function is pulling from.

Chris B