LeonardoMaranhãoFSilva
Posts: 0
Joined: Mon Jan 30, 2012 1:52 pm

How do I add a marker to a google map?

My Code (a javascript in the success event of a geolocation service component):
var map = new google.maps.Map(Tiggr('mapa'));

var location = new google.maps.LatLng(8.0000,34.0000);

var marker = new google.maps.Marker({
position: location,
map: map,
title:"Hello World!"
});

Error:
Uncaught TypeError: Cannot set property 'position' of undefined
Ci
On
J.Vh
Jmain.js:36
df.(anonymous function).mc.cmain.js:25
Nmain.js:10
ffmain.js:25
kfmain.js:25
(anonymous function)
gf.(anonymous function)
(anonymous function)main.js:25
bmain.js:11
df.(anonymous function).mcmain.js:25
Nmain.js:10
df.(anonymous function).mcmain.js:25
cf.(anonymous function).Idmain.js:24
df.(anonymous function).mcmain.js:25
hfmain.js:25
(anonymous function)

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How do I add a marker to a google map?

This works:

code
var location = new google.maps.LatLng(-25.363882,131.044922);

var myOptions = {
zoom: 4,
center: location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map($('div[dsid="mapa"]').get(0), myOptions);

var marker = new google.maps.Marker({
position: location,
map: map,
title:"Hello World!"
});
/code

There is difference when you use getElemetById() and Tiggr(). Tiggr is just a short cut to jQuery $('div[dsid="mapa"]').

More information: http://stackoverflow.com/questions/61.... So that's why you need to use .get(0).

However, I'm checking why Tiggr(id).get(0) doesn't work.

Jgc
Posts: 0
Joined: Wed Mar 07, 2012 8:58 pm

How do I add a marker to a google map?

Hi, do i need a separate GeoLocation widget for this code if I already have one containing code? Or can i use this in the same widget I already have?

And do i paste this code before or after the code that searches my users current location? Thanks!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How do I add a marker to a google map?

To place a marker using above code you don't need a Geolocation widget, just a Google Map component.

Jgc
Posts: 0
Joined: Wed Mar 07, 2012 8:58 pm

How do I add a marker to a google map?

I see.....Okay, so where would I put that code? A custom script? what kind of action do I use? blur, focus, click, etc.?

Jgc
Posts: 0
Joined: Wed Mar 07, 2012 8:58 pm

How do I add a marker to a google map?

I guess Im asking what kind of EVENT do i use to put the code into?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How do I add a marker to a google map?

I can be any event you want - it depends when you when to run the script. Go with click on a button first.

Jgc
Posts: 0
Joined: Wed Mar 07, 2012 8:58 pm

How do I add a marker to a google map?

I already have the click event being used for another script. What would be a viable second option for an event other than click?

My script so far shows the users current geo-location. If I were to put this script in the same place as my current geo-locate script, would I place this script on top of it, or below it?

And so I can just make sure I am reading things correctly, the first line of code....Thats where I specify my map coordinates, right?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How do I add a marker to a google map?

It really depends on your app, when do you want this particular feature to be invoked. The events I'm referring to are just standard HTML events. It's OK to do two things (actions) on one click.

Yes, the first line sets the coordinates.

Jgc
Posts: 0
Joined: Wed Mar 07, 2012 8:58 pm

How do I add a marker to a google map?

ok, I wanted to test the code with my code that I already used, and Im getting my alert window popping up like every 2 seconds, even with the break statement. Is there a way I can just let users know the app is seraching a location without the app stopping to let them know?

In other words, i want an alert to be seen so ppl know the app is working, but at the same time i want it to show ONE time instead of every 2 seconds and i want the app to search while the alert is shown, not stop till the user hits OK button.....Any ideas?

Return to “Issues”