Re: How to get center lat/lng individually?
Wasn't it dhpollack who wrote:
>
>I was wondering if there are any methods to get the current center
>lat/lng of a map individually as opposed to a coordinate like with
>map.getCenterLatLng(). Right now, I am using map.getCenterLatLng() then
>trying to use javascript to break up the string. This would work, but
>I'm having trouble removing the ( and ) from the string. So far this is
>what I've got:
>
> var centerPoint = "";
> centerPoint += map.getCenterLatLng();
> centerPoint.replace(/\(/g,'');
> centerPoint.replace(/ /g,'');
> var currentCenter = centerPoint.split(',');
>
>The problem is with the third line because it never finds the string (
>and if I don't escape the ( then the script breaks. Any help is greatly
>appreciated.
The easiest way is to NOT convert it to a string in the first place.
map.getCenterLatLng() returns a GPoint, but when you perform the string
concatenation operation, it causes the GPoint.toString() method to be
performed.
So perform the splitting first
var centreLat = map.getCenterLatLng().y;
var centreLng = map.getCenterLatLng().x;
If you actually need them to be strings you can then convert them by
string concatenation
var centreLatString = "" + centreLat;
or by explicitly invoking the .toString() method
var centreLngString = centreLng.toString();
--
Another quick fix from
The Blackpool Community Church Javascript Team
http://www.econym.demon.co.uk/googlemaps/
0 Comments:
Yorum Gönder
<< Home