How to get latitude and longitude from google maps v3 api?

前端 未结 6 700
孤街浪徒
孤街浪徒 2021-02-04 08:40

I am trying create a map using google maps v3 api. I have found the below code over internet and I want to show the latitude and logitude in map window instead of address.

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 09:14

    Where you have

      var address = '';
      if (place.address_components) {
        address = [
          (place.address_components[0] && place.address_components[0].short_name || ''),
          (place.address_components[1] && place.address_components[1].short_name || ''),
          (place.address_components[2] && place.address_components[2].short_name || '')
        ].join(' ');
      }
    
      infowindow.setContent('
    ' + place.name + '
    ' + address); infowindow.open(map, marker);

    Change the infowindow line to read

      infowindow.setContent('
    ' + place.name + '
    ' + place.geometry.location.lat() + ',' + place.geometry.location.lng());

提交回复
热议问题