从Google地方获取经度和纬度使用Javascript搜索api [英] Getting Latitude and Longitude from Google Places search api using Javascript

查看:102
本文介绍了从Google地方获取经度和纬度使用Javascript搜索api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何通过google地图位置搜索框api从搜索到的位置获取经度和纬度。 我使用与google演示相同的代码 - https://developers.google.com/maps/documentation/javascript/examples/places-searchbox

解决方案

 函数GetLatlong()
{
var geocoder = new google.maps.Geocoder();
var address = document.getElementById('textboxid')。value;

geocoder.geocode({'address':address},function(results,status){

if(status == google.maps.GeocoderStatus.OK){
var latitude = results [0] .geometry.location.lat();
var longitude = results [0] .geometry.location.lng();

}
});

您可以使用上面的函数来给出用户输入区域的纬度和经度。

How do I get the longitude and latitude from the searched location with the google maps place search box api.

Im using the same code as the google demo - https://developers.google.com/maps/documentation/javascript/examples/places-searchbox

解决方案

function GetLatlong()
    {
        var geocoder = new google.maps.Geocoder();
        var address = document.getElementById('textboxid').value;

        geocoder.geocode({ 'address': address }, function (results, status) {

            if (status == google.maps.GeocoderStatus.OK) {
                var latitude = results[0].geometry.location.lat();
                var longitude = results[0].geometry.location.lng();

            }
        });

You can use the above function which will give you the latitude and longitude for the area entered by user.

这篇关于从Google地方获取经度和纬度使用Javascript搜索api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆