Accuracy of lat/long

327 views
Skip to first unread message

chrisevans1001

unread,
Sep 20, 2009, 10:08:05 AM9/20/09
to Google Maps JavaScript API v3
Hi. I have my users clicking a location which sets a marker which in
turn returns a lat/long to a mysql database. Trouble is the lat/long
is longer than 6 decimal places. After the marker is set, I use:

map.set_center(location);

document.getElementById('lat').value = map.getCenter().lat();
document.getElementById('long').value = map.getCenter().lng();

How can I return a lat/lng of 6 decimal places.

Thanks.

pamela (Google Employee)

unread,
Sep 20, 2009, 10:10:27 AM9/20/09
to google-map...@googlegroups.com
Hi Chris-

Take a look at the toFixed function in JavaScript, you can call that
on your lat/lng values:
http://www.w3schools.com/jsref/jsref_tofixed.asp

- pamela

chrisevans1001

unread,
Sep 20, 2009, 10:24:54 AM9/20/09
to Google Maps JavaScript API v3
Thanks for your help!

On Sep 20, 3:10 pm, "pamela (Google Employee)" <pamela...@gmail.com>
wrote:

chrisevans1001

unread,
Sep 20, 2009, 11:17:20 AM9/20/09
to Google Maps JavaScript API v3
I seem to be struggling on a bit of code relating to this.

http://directory.konectinternet.com/images/maptest.html

When the page loads and it initializes you'll see an if statement
checks whether lat/lng coordinates exist already. If they do, it calls
geocodeLatLng(). In this instance, the co-ordinates do exist and so
geocodeLatLng is called. This then calls placeMarker which places a
marker on the map. :)

The problem is - somewhere, the co-ordinates initially supplied (as
can be seen in the code) get replaced with two new sets of co-
ordinates.

The reason I'm struggling is with exactly the same code but different
co-ordinates, it works fine.

http://directory.konectinternet.com/images/maptest2.html

The only difference is the co-ordinates are placed near a road. If the
initial co-ordinates are not near a road, this situation occurs every
time :-s.

Also, is there anyway to increase the accuracy of the marker
placement?

Cheers

On Sep 20, 3:24 pm, chrisevans1001 <chrisevans1...@googlemail.com>
wrote:

chrisevans1001

unread,
Sep 20, 2009, 4:40:59 PM9/20/09
to Google Maps JavaScript API v3
Aha! Figured it. The whole accuracy issue was irrelevant - it turns
out I'm geocoding a lat/lng which is completely pointless (well I
assume there are situations when it is required or it wouldn't be
included but I can't think of any!). I now just place marker directly
when coordinates are available.

Chris

On Sep 20, 4:17 pm, chrisevans1001 <chrisevans1...@googlemail.com>
wrote:

pamela (Google Employee)

unread,
Sep 20, 2009, 4:42:44 PM9/20/09
to google-map...@googlegroups.com
Right - geocoding a lat/lng is the process of reverse geocoding -
getting an address for a lat/lng. Most developers do not reverse
geocode for the situation you described. Glad you figured it out! :)

- pamela
Reply all
Reply to author
Forward
0 new messages