javascript/谷歌地图:将位置对象转换为字符串

javascript/google maps: convert location object to string

本文关键字:对象 转换 字符串 位置 谷歌地图 javascript      更新时间:2023-10-01

我正试图找出如何将以下对象从使用谷歌位置api转换为字符串

initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);

以上内容显示了您的位置。然而,我想不出一种方法来查看它是什么字符串,这样我就可以使用它了。当我提醒它时,我会得到未定义的结果,我尝试了常见的可疑属性,但它们不会显示。我需要弄清楚它是什么,这样我就可以把它输入到以"Boston"或lat-lon或类似字符串为输入的方向服务中。

Please refer the below link.

http://jsfiddle.net/y829C/1/

Here you can enter zip code and get the latitude and longitude.
var geocoder = new google.maps.Geocoder();
       geocoder.geocode({ 'address': addresscity }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    latitude = results[0].geometry.location.lat();
                    longitude = results[0].geometry.location.lng();
                 var myLatlng = new google.maps.LatLng(latitude, longitude);
                    var mapOptions = {
                 center: new google.maps.LatLng(latitude, longitude),
                  zoom: 8,
                 mapTypeId: google.maps.MapTypeId.ROADMAP
  };