Longitude and Latitude Javascript Question

274 views
Skip to first unread message

Scott Coffey

unread,
Jul 20, 2011, 4:28:10 PM7/20/11
to google-map...@googlegroups.com
Hello,
I am trying to pass the coordinates from the database to my javascript code. I tried posting it directly in this post but my thread got rejected.... If you view the source here:

http://www.huarencommunity.com/chinacity/city2.aspx?cityid=6

You can see that I am pulling the longitude and latitude from the 2 ASP labels I have, and the labels show the coordinates underneath where the map would be loading. Is my JavaScript wrong or is it another problem?

Andrew Leach

unread,
Jul 20, 2011, 5:48:13 PM7/20/11
to google-map...@googlegroups.com

I can't find where you actually call the initialize() Javascript function.

However, even when it is called (I did that manually), your values are
strings, not numbers and you need to parseFloat() them.

Scott Coffey

unread,
Jul 22, 2011, 3:05:48 PM7/22/11
to google-map...@googlegroups.com, andrew....@gmail.com
Thanks for the response!

It's probably not the best practice, but the page is a child page of a Masterpage, so I am initializing in a second 'body' tag.

I changed the code to handle the float:
            var latitude = parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_lblLatitude').value);
            var longitude = parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_lblLongitude').value);
            var latlng = new google.maps.LatLng(latitude, longitude);

Doesn't seem to work, coordinates are still correct underneath the google map.
http://www.huarencommunity.com/chinacity/city2.aspx?cityid=6

Thanks!

geoco...@gmail.com

unread,
Jul 22, 2011, 3:40:10 PM7/22/11
to Google Maps JavaScript API v3
but map.getCenter() returns (NaN, NaN) so they aren't being used.

-- Larry
>
> Thanks!

Rossko

unread,
Jul 22, 2011, 3:46:12 PM7/22/11
to Google Maps JavaScript API v3
>             var latitude = parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_lblLatitude')­.value);

Your element is a <span>, I don't think they have 'value' property.
example suggestion from googling
http://www.vbforums.com/showthread.php?t=339864

Scott Coffey

unread,
Jul 22, 2011, 5:12:20 PM7/22/11
to google-map...@googlegroups.com
I tried some more things as you all suggested and nothing. :(

Maybe it'll be easier to just describe what I'm trying to do.

There is 2 ways I see to do this:
  1. Pass the City Name to the javascript and set the map that way. (What I'd really like to do, seems the simplest)
  2. Pass the Coordinates to the javascript and set the map that way.
Both would be loaded dynamically from database, (using c# / asp.net) as the page loads, no button/link clicking.

I've been trying to understand the API in javascript, but javascript is basically brand new to me and I don't  really follow it that well.

geoco...@gmail.com

unread,
Jul 22, 2011, 7:11:43 PM7/22/11
to Google Maps JavaScript API v3
On Jul 22, 5:12 pm, Scott Coffey <scott.coffe...@gmail.com> wrote:
> I tried some more things as you all suggested and nothing. :(
>
> Maybe it'll be easier to just describe what I'm trying to do.
>
> There is 2 ways I see to do this:
>
>    1. Pass the City Name to the javascript and set the map that way. (What
>    I'd really like to do, seems the simplest)

Example:
http://www.geocodezip.com/GMapsExampleV3b.html

>    2. Pass the Coordinates to the javascript and set the map that way.

Lots of examples that do that, have you looked at the documentation?

-- Larry

Rossko

unread,
Jul 22, 2011, 9:02:27 PM7/22/11
to Google Maps JavaScript API v3
> I tried some more things as you all suggested and nothing. :(

The one we can see is still trying to get the .value of a <span>
Won't work. Not a maps problem.

You have invalid multiple <body> sections too

Andrew Leach

unread,
Jul 23, 2011, 4:44:23 AM7/23/11
to google-map...@googlegroups.com
On 22 July 2011 20:05, Scott Coffey <scott.c...@gmail.com> wrote:
> Thanks for the response!
>
> It's probably not the best practice, but the page is a child page of a
> Masterpage, so I am initializing in a second 'body' tag.

It's definitely definitely not best practice. Some browsers use the
first and ignore the second; others will use the second and might or
might not do anything with markup occurring before that. The results
are undefined. Look into using window.onload to set the onload action.

Reply all
Reply to author
Forward
0 new messages