谷歌的地理code转换市,州为纬度经度 [英] Google's GeoCode Convert City, STATE into Latitude Longitude

查看:222
本文介绍了谷歌的地理code转换市,州为纬度经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code以异步方式工作。我只把它设置为一个城市,州转换为纬度和经度。然后,该值被惊动了。

我怎么能写,实际上这些返回值的函数?

  VAR地图;
VAR地理codeR;函数初始化(){  地理codeR =新GClientGeo codeR();}//当地理codeR返回addAddressToMap()被调用
//答案。它增加了一个标记到地图以开放的信息窗口
//显示地址和格式恰当全国code。
功能addAddressToMap(响应){
  //map.clearOverlays();
  如果(!反应|| response.Status。code!= 200){
    警报(对不起,我们无法地理code该地址);
  }其他{
    地方= response.Placemark [0];    纬度= place.Point.coordinates [0];
    经度= place.Point.coordinates [1];    警报(纵横+纬度+经度+经度);  }
}功能showLocation(地址){
  地理coder.getLocations(地址,addAddressToMap);
}


解决方案

返回从回调的值将不会做任何事情。如果要存储这些值的地方只是做回调。你能做到这一点在当前的code,如果你只是在顶部在哪里申报地图和地理codeR瓦尔声明经度和纬度。

The following code works asynchronously. I only have it set up to convert a City, State into latitude and longitude. That value is then alerted.

How can I write a function that actually returns these values?

var map;
var geocoder;

function initialize() {

  geocoder = new GClientGeocoder();

}

// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
  //map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Sorry, we were unable to geocode that address");
  } else {
    place = response.Placemark[0];

    latitude = place.Point.coordinates[0];
    longitude = place.Point.coordinates[1];

    alert("Latitude " + latitude + " Longitude" + longitude);

  }
}

function showLocation(address) {
  geocoder.getLocations(address, addAddressToMap);
}

解决方案

Return those values from the callback won't doing anything. If you want to store those values somewhere just do it in the callback. You could do it in your current code if you just declare latitude and longitude at the top where declare the map and geocoder vars.

这篇关于谷歌的地理code转换市,州为纬度经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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