Page 1 of 4

How do I add a marker to a google map?

Posted: Mon Jan 30, 2012 3:47 pm
by LeonardoMaranhãoFSilva

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)


How do I add a marker to a google map?

Posted: Mon Jan 30, 2012 6:28 pm
by maxkatz

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.


How do I add a marker to a google map?

Posted: Thu Mar 15, 2012 6:53 pm
by Jgc

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!


How do I add a marker to a google map?

Posted: Thu Mar 15, 2012 9:50 pm
by maxkatz

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


How do I add a marker to a google map?

Posted: Thu Mar 15, 2012 10:35 pm
by Jgc

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


How do I add a marker to a google map?

Posted: Thu Mar 15, 2012 10:55 pm
by Jgc

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


How do I add a marker to a google map?

Posted: Thu Mar 15, 2012 11:27 pm
by maxkatz

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


How do I add a marker to a google map?

Posted: Fri Mar 16, 2012 2:35 pm
by Jgc

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?


How do I add a marker to a google map?

Posted: Fri Mar 16, 2012 4:02 pm
by maxkatz

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.


How do I add a marker to a google map?

Posted: Fri Mar 16, 2012 4:28 pm
by Jgc

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?