Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

If I have a link with address and coordinate information tied to it can I populate a marker on google map?

Posted on 2014-10-09
5
130 Views
Last Modified: 2014-10-09
I wanted to see how I can have separate list of links with possibly...

<script>
Google map general script which I have working...
</script>

<div id="map-canvas"></div>
<a href="#" data-address="my address" data-lat="latitude data" data-lng="longitude data">Whatever Link</a> to

The idea is to populate a marker on the map. I can't seem to find any examples of this out there.

Thx for any help!
0
Comment
Question by:brihol44
  • 2
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40371225
populate a marker on the map

Do you mean, set, add, put, place a marker on the map?
0
 

Author Comment

by:brihol44
ID: 40371278
Yep! Thx!
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40371339
Test page : http://jsfiddle.net/kuxL5hux/

// GLOBAL VARIABLE
var map = null;

function initialize() {
    var mapOptions = {
          zoom: 10,
          center: new google.maps.LatLng(16.1186017, -61.5229536),
          mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
}

window.onload = function() {
    document.getElementsByTagName("a")[0].onclick = function() {
        var isNotAlreadyAddedToTheMap = !this.getAttribute("data-done");
        if(isNotAlreadyAddedToTheMap) {
            var myLatlng = new google.maps.LatLng(this.getAttribute("data-lat"), this.getAttribute("data-lng"));
            var marker = new google.maps.Marker({
                position: myLatlng,
                map: map,
                title: this.getAttribute("data-address")
            });
            this.setAttribute("data-done", true);
        }
    }
}

Open in new window

0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 40372229
Here is a good example at my personal website

http://www.javascriptjournal.com/gmaps/index.html

I think,  this will you give an idea who google map API works.
0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 40372234
Feel free to look the code and reuse.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 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