Google Maps API - Custom Icon keeps moving West as you zoom out.

Posted on 2006-05-09
Last Modified: 2010-05-18
I am using the following function to draw the custom icon on my map.  I had to change the values in the CreateBusmarker function for the icon.IconSize and icon.IconAnchor properties to get it to look correct and to be placed at the exact correct point.  The problem is, that I set those values based on where the icon was showing when I was zoomed ALL the way in on the map.  The further you zoom out, the further west the icon gets placed.  It moves so much that when you zoom out to the entire U.S. it doesn't even look like it's in the right state anymore.  If I shrink the icon down and use icon.iconSize = new GSize(12,20) and icon.iconAnchor = new  GPoint(6,20) it works perfectly but the icon is WAY too small.  I have pasted what I think is the relevant code below.  If I omitted anything you need to see, just let me know and I'll post the whole thing if I have to.  Anyone have any suggestions?

         <script type="text/javascript">

            // Create the marker and corresponding information window
            function createInfoMarker(point, address) {
               var marker = new GMarker(point);
               GEvent.addListener(marker, "click",
                  function() {
               return marker;

            // Create the Bus marker with a custom icon and information window
          function createBusMarker(point, address) {
               var marker = new GMarker(point);
               // Create the custom icon
               var icon = new GIcon();
               icon.image = "";
               icon.shadow = "";
               icon.iconSize = new GSize(40, 40);
               icon.shadowSize = new GSize(50, 40);
               icon.iconAnchor = new GPoint(32, 40);
               icon.infoWindowAnchor = new GPoint(5, 1);
               var marker = new GMarker(point, icon);
               GEvent.addListener(marker, "click",
                  function() {
               return marker;

            var map = new GMap(document.getElementById("map"));
            map.centerAndZoom(new GPoint(<%=szLong%>, <%=szLat%>), 5);
            //HNET Express Current Location
          var point = new GPoint(<%=szLong%>, <%=szLat%>);
          address = "HNET Express";
          var marker = createBusMarker(point, address);
          map.addControl(new GLargeMapControl());
          map.addControl(new GMapTypeControl());
Question by:Swindle
    LVL 11

    Author Comment

    I'm still having this problem.  If anyone has any suggestions at all I would love to hear it.  
    LVL 10

    Accepted Solution


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now