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

前端 未结 6 699
孤街浪徒
孤街浪徒 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:19

    Much simpler solution will be :

    var address = "New Delhi"
    $.ajax({
      url:"http://maps.googleapis.com/maps/api/geocode/json?address="+address+"&sensor=false",
      type: "POST",
      success:function(res){
         console.log(res.results[0].geometry.location.lat);
         console.log(res.results[0].geometry.location.lng);
      }
    });
    

    Cheers

提交回复
热议问题