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 8075899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:08:59+00:00 2026-06-05T15:08:59+00:00

I’m writing a custom overlay for a Google Map. I have a serious of

  • 0

I’m writing a custom overlay for a Google Map. I have a serious of lat-long points, and I want to images with arrows pointing to and from them. I’m following Google’s custom overlay tutorial (https://developers.google.com/maps/documentation/javascript/overlays#CustomOverlays).

In my overlay’s “constructor,” this line fails:
‘this.setMap(this.map_);’

What do I need to do to make it work?

This is my overlay’s “constructor.” The broken line is at the bottom. All of the calls to “alert” are in there as I’m testing. The last call isn’t reached, which is why I think ‘this.setMap()’ isn’t working.

 //This serves as a constructor for a link overlay
 function LinkOverlay(startNodeCoordinates, endNodeCoordinates, map)
 {
    alert("constructor start");
    this.map_ = map;

    //These are the lat-long coordinates of where the link starts and ends
    this.startNodeCoordinates_ = startNodeCoordinates;
    this.endNodeCoordinates_ = endNodeCoordinates;

    alert("constructor coordinates stored");

    // We define a property to hold the image's
    // div. We'll actually create this div
    // upon receipt of the add() method so we'll
    // leave it null for now.
    this.div_ = null;

    alert("constructor div saved");

    //We need to know if we draw the arrow up or down and left or right.
    //We calculate this by finding the bearing between the two nodes. If
    //the bearing is N to NE, then the arrow goes up and to the right,
    //for example. If the bearing is E to SE, then the arrow goes down
    //and to the right, and so on.

    //Calculate bearing
    /*
     * This algorithm determines the bearing (or angle) between two coordinate points.
     * It was adapted from http://www.movable-type.co.uk/scripts/latlong.html
     */
    alert("constructor calculating bearing")
    this.bearing_ = null;
    var lat1 = this.startNodeCoordinates_.lat();
    var lat2 = this.endNodeCoordinates_.lat();
    var dLon = this.startNodeCoordinates_.lng() - this.endNodeCoordinates_.lng();
    var y = Math.sin(dLon) * Math.cos(lat2);
    var x = Math.cos(lat1)*Math.sin(lat2) -
        Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
    this.bearing_ = Math.atan2(y, x);

    alert("constructor bearing found (bearing = " + this.bearing_ + ")");

    this.arrowUp_ = null;
    this.arrowRight_ = null;
    this.image_ = null;

    alert("constructor picking image");

    if((this.bearing_ >= 0 && this.bearing_ < (Math.PI * 0.5)) || this.bearing_ == (Math.PI * 2))
    {
        alert("constructor NE");
        //If bearing is N to NE, the arrow goes up and to the right
        this.arrowUp_ = new Boolean(true);
        this.arrowRight_ = new Boolean(true);
        this.image_ = "../../Content/map_images/link_overlay/up_right_black.png";
    }
    else if(this.bearing_ >= (Math.PI * 0.5) && this.bearing_ < Math.PI)
    {
        alert("constructor SE");
        //If bearing is E to SE, the arrow goes down and to the right
        this.arrowUp_ = new Boolean(false);
        this.arrowRight_ = new Boolean(true);
        this.image_ = "../../Content/map_images/link_overlay/down_right_black.png";
    }
    else if(this.bearing_ >= Math.PI && this.bearing_ < (Math.PI * 1.5))
    {
        alert("constructor SW");
        //If bearing is S to SW, the arrow goes down and to the left
        this.arrowUp_ = new Boolean(false);
        this.arrowRight_ = new Boolean(false);
        this.image_ = "../../Content/map_images/link_overlay/down_left_black.png";
    }
    else
    {
        alert("constructor NW");
        //If bearing is W to NW, the arrow goes up and to the left
        this.arrowUp_ = new Boolean(true);
        this.arrowRight_ = new Boolean(false);
        this.image_ = "../../Content/map_images/link_overlay/up_left_black.png";
    }

    alert("constructor adding to map");

    // Explicitly call setMap() on this overlay
    this.setMap(this.map_);

    alert("constructor end");
 }

 //This "subclasses" a link overlay from Google Map's OverlayView class
 LinkOverlay.prototype = new google.maps.OverlayView();

This is the code that creates new LinkOverlays (in Razor syntax):

@:var startNodeCoordinates = new google.maps.LatLng('@startNode.Latitude', '@startNode.Longitude');
@:var endNodeCoordinates = new google.maps.LatLng('@endNode.Latitude', '@endNode.Longitude');
@:var routeLine = new LinkOverlay(startNodeCoordinates, endNodeCoordinates, networkMap);
  • 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-05T15:09:00+00:00Added an answer on June 5, 2026 at 3:09 pm

    I had the same problem. I fixed it using ‘new’ to instanciate my custom overlay.
    In your case, are you sure that when instanciate your overlay, you use :

    linkOverlay = new LinkOverlay(s, e, map)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.