标签: google-geocoder

使用javascript闭包将参数附加到匿名函数中的默认参数

我想在Google地理编码器API调用中添加一些额外的参数,因为我在循环中运行它,但我不知道如何将闭包参数附加到已经具有默认参数的匿名函数,该默认参数通过调用传入API.

例如:

for(var i = 0; i < 5; i++) {
     geocoder.geocode({'address': address}, function(results, status) {
         // Geocoder stuff here
     });
}
Run Code Online (Sandbox Code Playgroud)

我希望能够在传递的geocoder.geocode()匿名函数中使用i的值,但是如果我}(i));在第4行使用了一个闭包,例如它将替换第一个会破坏地理编码器的参数.

有没有办法可以使用闭包,或者将i的值传递给匿名函数?

有效的我想做的是:

geocoder.geocode({'address': address}, function(results, status, i) {
    alert(i); // 0, 1, 2, 3, 4
}(i));
Run Code Online (Sandbox Code Playgroud)

但工作:-)

javascript closures google-geocoder

5
推荐指数
1
解决办法
3540
查看次数

Google将地理编码API V3映射为不返回javascript函数的结果

我正在尝试使用Google地理编码器API V3根据用户指定的地址在地图上绘制位置,代码如下.

当我直接提出请求时(例如http://maps.googleapis.com/maps/api/geocode/json?address=peterborough&sensor=false),我得到了预期的回复.但是,当我使用下面的代码发出相同的请求时,在getLatLong函数退出后,中间点变量始终是未定义的.

我做错了什么?

function loadFromSearch(address) 
{
  midpoint = getLatLong(address);
  mapCentre = midpoint;
  map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
  ...
}


function getLatLong(address) 
{
  var result;
  var url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + encodeURIComponent(address) + '&sensor=false'
  $.getJSON(url,
  function (data){
     if (data.status == "OK")
     {
        result = data.results[0].geometry.location;
     }
  });
  return result;
}
Run Code Online (Sandbox Code Playgroud)

================================================== ================================

鉴于回复,我现在已将代码更新为以下内容.我仍然没有得到任何结果,在Firebug中设置断点结果= data.results [0] .geometry.location; 永远不会受到打击

function loadFromSearch(address) 
{
  midpoint = getLatLong(address, loadWithMidpoint);    
}

function getLatLong(address, callback)
{
   var result;
   var url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + encodeURIComponent(address) + …
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-maps geocoding google-geocoder

5
推荐指数
1
解决办法
3万
查看次数

在实现Runnable的类中获取上下文

我有一个Android的应用程序,在与UI不同的线程中(实现Runnable)

我收到一些数据(纬度和经度形式的GPS数据)和这个数据我

想通过传递给Geocoder找到正确的地址......之后Geocoder返回的地址将它存储在数据库中:

我是这样做的:

public class Client implemets Runnable{


public void run()
{

Geocoder myLocation=new Geocoder(getApllicationContext,Locale.getDefault());



}

}
Run Code Online (Sandbox Code Playgroud)

但我在这里得到错误:

Geocoder myLocation=new Geocoder(getApplicationContext,Locale.getDefault());
Run Code Online (Sandbox Code Playgroud)

Runnable不知道谁getApplicationContext是.....我尝试用"this"而不是同样的故事......

现在哪个是传递给Geocoder构造函数的正确上下文????

以下是Geocoder构造函数的外观:

Geocoder myLocation =new Geocoder(context,locale);
Run Code Online (Sandbox Code Playgroud)

在我的活动中,我这样做:

public class Server2 extends Activity {


public void onCreate(Bundle icicle) {


ClientThread_special client = new ClientThread_special(db);//here is where I start thread


        new Thread(client).start();
}


}
Run Code Online (Sandbox Code Playgroud)
public class ClientThread_special implements Runnable {



 public ClientThread_special(DBAdapter db){

     this.db=db;
    }


 public void run() 

{

Geocoder myLocation=new Geocoder(getApllicationContext,Locale.getDefault());


}


}
Run Code Online (Sandbox Code Playgroud)

我该如何修改构造函数

public ClientThread_special(DBAdapter …
Run Code Online (Sandbox Code Playgroud)

android android-context google-geocoder

5
推荐指数
1
解决办法
7884
查看次数

从5位邮政编码获得9位数的邮政编码,programmatic,api

我有5位数的邮政编码,这些邮政编码是从谷歌地图Api中检索出来的.

我的困境是我必须连接到一个也包含地址的远程数据库.如果该数据库中不存在该地址,我必须编写它,如果它存在,那么除了存储数据库已分配给该地址的ID之外,我什么都不做.问题出现,因为检查此数据库的api不带通配符,该数据库中的地址有9位邮政编码(5 + 4),并且不会返回地址的其余部分与我的地址匹配5位邮政编码.

远程系统会告诉我该地址与我发送的地址不存在.

因此,为了防止将重复地址写入数据库,我需要在发送之前找到我所拥有的9位数的邮政编码.

怎么做?是否有确定5位数地址的最后4位数的公式?USPS是否有API?人口普查是否有一张巨大的桌子?

洞察力赞赏

api usps geocode street-address google-geocoder

5
推荐指数
1
解决办法
2万
查看次数

反向地理编码 - 服务不可用 - 重新启动设备无法明确解决 - 批评我的手动反向地理编码

有时我会Service Not Available在我的申请中遇到例外情况.大多数时候,没有问题.但有时它会发生.(该应用程序仍在开发中)

解决问题的唯一方法是重启手机.关于支持论坛的相关问题38009.但我从评论中理解的是,重启设备可以永远解决问题.

它是否正确?
因为在我的情况下,错误可以返回(频率:我认为每月一次或两次,我在这个应用程序上是全职).

没有办法从应用程序内部重新启动地理编码器

我唯一的解决方案是提供一个替代解决方案,以防万一"手动"获取地址,如下所示.你有更好的吗?

    Dbg.d(TAG, "=== address_info FetchLocationTask - doInBackground");
new Thread(new Runnable() {

    @Override
    public void run() {
        Looper.prepare();
        mHandler = new Handler();
        Looper.loop();
    }
}).start();

    /**
     * Implementation of a second method in case of failure:
     * 
     */
    double lat = Double.parseDouble(args[0]);
    double lng = Double.parseDouble(args[1]);
    String address = String.format(Locale.ENGLISH,
            "http://maps.googleapis.com/maps/api/geocode/json?latlng="+Double.toString(lat)+","+Double.toString(lng)+"&sensor=true&language="+Locale.getDefault().getCountry(), lat, lng);
    Dbg.d(TAG, "fetching path : "+ address);


    HttpGet httpGet = new HttpGet(address); …
Run Code Online (Sandbox Code Playgroud)

android reverse-geocoding google-geocoder service-not-available

5
推荐指数
1
解决办法
3672
查看次数

Google地理编码API会在响应中返回错误的语言

我的项目在乌克兰敖德萨请求地理编码API以获取坐标并更正完整地址.

我可以请求用俄语或乌克兰语添加language=ru(language=uk)参数来响应HTTP请求.从今天开始,无论我在请求中指定哪种语言,我都会在乌克兰语中获得街道名称.

例子.

请求俄语: https://maps.googleapis.com/maps/api/geocode/json?address=??????????, ??????, ???????&language=ru

答复的相关部分:

"results" : [
  {
     "address_components" : [
        {
           "long_name" : "?????????? ??????",
           "short_name" : "?????????? ??????",
           "types" : [ "route" ]
        },
        {
           "long_name" : "??????????? ?????",
           "short_name" : "??????????? ?????",
           "types" : [ "sublocality_level_1", "sublocality", "political" ]
        },
        {
           "long_name" : "?????",
           "short_name" : "?????",
           "types" : [ "locality", "political" ]
        },
        {
           "long_name" : "???????? ????????",
           "short_name" : "???????? ????????",
           "types" : [ "administrative_area_level_3", "political" ] …
Run Code Online (Sandbox Code Playgroud)

geolocation google-geocoder google-geocoding-api

5
推荐指数
1
解决办法
3256
查看次数

如何通过google javascript api获取知道place_id的位置坐标

我知道place_id,我需要知道它的坐标.

我可以 GET https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJOwE7_GTtwokRFq0uOwLSE9g&key=KEY_GOES_HERE

这给了我这样的东西:

```   "results" : [
      {
         "address_components" : [...],
         "formatted_address" : "New York County, NY, USA",
         "geometry" : {
            "bounds" : {...},
            "location" : {
               "lat" : 40.7830603,
               "lng" : -73.9712488
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {...}
         },
         "partial_match" : true,
         "place_id" : "ChIJOwE7_GTtwokRFq0uOwLSE9g",
         "types" : [...]
      }
   ],
   "status" : "OK"
```
Run Code Online (Sandbox Code Playgroud)

但我需要通过javascript api来做.

我的页面上没有任何地图,只需要获取坐标.

google-maps google-maps-api-3 google-geocoder

5
推荐指数
2
解决办法
1万
查看次数

从给定的城市Google地方API检索所有地区和子地区

我正在寻找一种网络服务或Google地方API类型的插件来检索地理位置,子地区和给定城市名称的区域.

一直在尝试使用谷歌和地名,但无法通过它.

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=hyderabad&types=(locality)&language=en_US&key=My_KEY


https://maps.googleapis.com/maps/api/geocode/json?/?address=hyderabad&key=My_KEY
Run Code Online (Sandbox Code Playgroud)

尝试过这两种方式.任何帮助,将不胜感激.

google-geocoder google-geocoding-api google-places-api

5
推荐指数
1
解决办法
8334
查看次数

Python-获取城市人口的名称

我可以用来获取城市人口的优质python API是什么?我尝试使用地址解析器,但无法正常工作-不知道为什么。

geocoder.population('San Francisco, California')
Run Code Online (Sandbox Code Playgroud)

退货

'module' object has no attribute 'population'
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况,我该如何解决?

或者,是否可以为此使用其他Python API?

python geocoding geography google-geocoder google-geocoding-api

5
推荐指数
1
解决办法
575
查看次数

EditText.setText(String)使数组超出范围

我有一个从地址解析器获取位置地址的应用,它在线程内执行请求。调用getActivity()。runOnUiThread时,我已经在字符串变量中包含了来自geocoder的地址响应,然后检查它是否为空,然后开始将其值分配给视图中的字段:

  getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (isAdded())
                                    if (!TextUtils.isEmpty(strAddress)){
                                        et.setFocusable(false);
                                        et.setFocusableInTouchMode(false);
                                        et.setText(strAddress);
                                        et.setTextColor(getResources().getColor(
                                                android.R.color.black));
                                        et.setFocusable(true);
                                        et.setFocusableInTouchMode(true);
                                    } else {
                                        et.setTextColor(getResources().getColor(
                                                android.R.color.black));
                                    }
                                etSource.setEnabled(true);
                            }
                        });
Run Code Online (Sandbox Code Playgroud)

在这条线上:

et.setText(strAddress);
Run Code Online (Sandbox Code Playgroud)

错误

ArrayIndexOutOfBounds:设置范围-1

抛出并间歇性地发生,为什么会发生?

根据要求编辑

  java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
                                                                         at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1270)
                                                                         at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684)
                                                                         at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:677)
                                                                         at android.text.Selection.setSelection(Selection.java:76)
                                                                         at android.widget.Editor$SelectionModifierCursorController.resetDragAcceleratorState(Editor.java:5689)
                                                                         at android.widget.Editor$SelectionModifierCursorController.resetTouchOffsets(Editor.java:5679)
                                                                         at android.widget.Editor.sendOnTextChanged(Editor.java:1280)
                                                                         at android.widget.TextView.sendOnTextChanged(TextView.java:8220)
                                                                         at android.widget.TextView.setText(TextView.java:4494)
                                                                         at android.widget.TextView.setText(TextView.java:4348)
                                                                         at android.widget.EditText.setText(EditText.java:89)
                                                                         at android.widget.TextView.setText(TextView.java:4323)
                                                                         at library.fragments.MapFragment$17$1.run(MapFragment.java:2156)
                                                                         at android.os.Handler.handleCallback(Handler.java:751)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:159)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6097)
                                                                         at java.lang.reflect.Method.invoke(Native Method) …
Run Code Online (Sandbox Code Playgroud)

java multithreading android google-geocoder

5
推荐指数
0
解决办法
557
查看次数