获取上使用谷歌地图的销code中的纬度和经度

问题描述:

我要装载给出的销code或地区code一个谷歌地图上的位置的要求。我已经使用地理codeR方法来找到使用给定的地址的经纬度尝试。这工作时被赋予一个位置或区域,但不工作的销code(具体印度)。是有任何方法或方式找到使用销code进行给定的区域的经度和纬度。

I have a requirement to loading a Google map location given the pin code or area code. I've tried using the Geocoder method to find the latitude and longitude using a given address. This works when a location or area is given, but is not working for the pincode (specifically India). Is there is any method or way to find the latitude and longitude of a given area using the pincode.

这是具体到一个地图加载在Android上,使用的MapView。

This is specific to a map to be loaded on android, using the mapview.

在code,我写给定为:

The code i've written is given as:

package com.example.geocodingexample;

import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {
MapView mapView;
MapController mapController;
GeoPoint p;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mapView = (MapView) findViewById(R.id.mapview);
    mapController = mapView.getController();
    mapView.setBuiltInZoomControls(true);
    mapController = mapView.getController();
    mapController.setZoom(14);
    Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
    try {
        List<Address> addresses = geoCoder.getFromLocationName("karnataka",
                1);
        String add = "";
        if (addresses.size() > 0) {
            p = new GeoPoint((int) (addresses.get(0).getLatitude() *    1E6),
                    (int) (addresses.get(0).getLongitude() * 1E6));
            mapController.animateTo(p);
            mapView.invalidate();
            Log.i("latitude obtained", String.valueOf(p.getLatitudeE6()));
            Log.i("longitude obtained", String.valueOf(p.getLongitudeE6()));
            Toast.makeText(this, "lat obtained", Toast.LENGTH_SHORT).show();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

}

当你增加方法签名的位置数它的工作原理。

It works when you increase the number of location in method signature.

 getFromLocationName("karnataka",
                        5);

它会给你经度和纬度。
 例如: -

it will give you latitude and longitude. Ex: -

    public void  findLocationName()
        {
     try {
    Geocoder gcd = new Geocoder(this, Locale.getDefault());
    List<Address> addresses;

    addresses = gcd.getFromLocationName("110002",5);


    for(int i=0;i<addresses.size();i++){
    Log.e("","in loop");
    Log.e("","lat :,,,,,,,,,,,,,"+addresses.get(i).getLatitude()+"  long............"+addresses.get(i).getLongitude());     
Toast.makeText(this, "lat : "+addresses.get(i).getLatitude(),1).show();
 Toast.makeText(this, "long : "+addresses.get(i).getLongitude(),1).show();
  }

     }
  catch (IOException e) {e.printStackTrace();}
    }