Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:29:10+00:00 2026-06-05T06:29:10+00:00

I am trying to create a map with custom markers. When heights and widths

  • 0

I am trying to create a map with custom markers.

When heights and widths are all the same, everything works fine. If I change one of them to be bigger (2x), that marker starts to behave funny – it’s partially rendered on map, it disappears and reappears when zooming in/out, on some zoom levels it looks ok. Input images are all 128×128, I am scaling them to 32×32 but i would like some of them to be 64×32

Here’s main function for adding markers (I commented out things that I tried before):

jQuery(xml).find("marker").each(function(){
var name = jQuery(this).find('name').text();
var address = jQuery(this).find('address').text();

// create a new LatLng point for the marker
var lat = jQuery(this).find('lat').text();
var lng = jQuery(this).find('lng').text();
var twidth = jQuery(this).find('width').text();
var theight = jQuery(this).find('height').text();
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
var imgPath = jQuery(this).find('icon').text();

var hw = twidth/2;
var hh = theight/2;
var imageForMarker = new google.maps.MarkerImage(
    imgPath,
    null,     //new google.maps.Size(128, 128),
    // The origin for this image is 0,0.
    null,     //new google.maps.Point(0,0),
    // The anchor for this image is at the centre
    null,    //new google.maps.Point(hw, hh),
    // Scaled size
    new google.maps.Size(twidth, theight));

    // extend the bounds to include the new point
    MYMAP.bounds.extend(point);

    var marker = new google.maps.Marker({
            position: point,
            map: MYMAP.map,
            icon: imageForMarker,
            zIndex:0
        });

        citiesArray.push(marker);

        var html='<strong>'+name+'</strong.><br />'+address+'<br><img src="http://chart.apis.google.com/chart?cht=qr&chs=200x200&chl=http%3A//maps.google.com/maps%3Fq=%26ll%3D'+lat+'%2C'+lng+'%26z%3D14&chld=H|0">';

        google.maps.event.addListener(marker, 'click', function() {

        if(infoWindow)
            infoWindow.close();
        infoWindow = new google.maps.InfoWindow();

            infoWindow.setContent(html);

            infoWindow.open(MYMAP.map, marker);


        });

        MYMAP.map.fitBounds(MYMAP.bounds);

    });

xml is this:

<?xml version="1.0"?>
<markers>

<marker>
<name>name1</name>
<address></address>
<lat>54.721844</lat>
<lng>17.41024</lng>
<width>32</width>
<height>32</height>
<icon>park2.png</icon>
</marker>

( ...)

<marker>
<name>name2</name>
<address></address>
<lat>50.417408112618686</lat>
<lng>23.491015625</lng>
<width>32</width>
<height>32</height>
<icon>park.png</icon>
</marker>

</markers>

here’s MYEDIT definition + initialization:

var infoWindow;
var MYMAP = {
map: null,
bounds: null,
iWindow: null
}

MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
zoom:zoom,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map(jQuery(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
}

test bed is at:

http://null-zero.com/test/markers/markers.html

IMPORTANT: you have to scroll down, tick CITIES, then at the top of the map near GDANSK a castle should appear – it’s broken (top part of the castle is visible), strange things happen when you zoom in/out.

There are two PlaceMarkers functions – the bottom one uses different width/height and is broken (placeMarkersCities)

Any ideas what causes it and how to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:29:11+00:00Added an answer on June 5, 2026 at 6:29 am

    Your current code is

    var twidth = jQuery(this).find('width').text();
    var theight = jQuery(this).find('height').text();
    ...
    new google.maps.Size(twidth, theight));
    

    But Size takes two Numbers. Odd things have been known to happen when maps objects are fed the wrong parameter type. In this case, you only convert some data from Strings to Numbers. You don’t convert twidth and theight.

    I suggest converting the data when you read it

    var lat = parseFloat(jQuery(this).find('lat').text());
    var lng = parseFloat(jQuery(this).find('lng').text());
    var twidth = parseInt(jQuery(this).find('width').text());
    var theight = praseInt(jQuery(this).find('height').text()); 
    

    rather than when you use it (as in your current code)

    var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
    

    because then it’s done once and you don’t have to remember it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a google map with custom icon markers. I need
I'm trying to create a custom javascript class that inherits from google.maps.Map (V3 API).
I am trying to create a custom google map using Longitudes and Latitudes that
I am trying to create a map with 3 different markers, but currently each
I'm trying to create a map, where the key is an int , and
I'm trying to create a mutable Map with a default that creates a new
I am trying to create a wpf control that will display a map image
I am trying to create a simple animation viewer for a sequence of map
I am trying to create a Google Maps application that has the map of
I'm trying to create my own custom validator class that I can check the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.