Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从谷歌地图标记获取电话号码_Android_Google Maps_Map_Infowindow_Marker - Fatal编程技术网

Android 从谷歌地图标记获取电话号码

Android 从谷歌地图标记获取电话号码,android,google-maps,map,infowindow,marker,Android,Google Maps,Map,Infowindow,Marker,我在android设备上使用谷歌地图,我正在从markes获取信息,我能够获取标记标题和制造商代码片段,但无法获取电话号码信息,请帮助我,提前感谢 package com.avion.mapdemo; 公共类MainActivity扩展了活动在InfoWindowClickListener上的实现{ // Google Map private GoogleMap googleMap; MarkerOptions markerOptions; LatLng latLng; GPSTracker

我在android设备上使用谷歌地图,我正在从markes获取信息,我能够获取标记标题和制造商代码片段,但无法获取电话号码信息,请帮助我,提前感谢

package com.avion.mapdemo;
公共类MainActivity扩展了活动在InfoWindowClickListener上的实现{

// Google Map
private GoogleMap googleMap;
MarkerOptions markerOptions;
LatLng latLng;
GPSTracker gps;
Address adrs;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
        // Loading map

        initilizeMap();

        // my location...
        googleMap.setMyLocationEnabled(true);

        // room setting from 2(min) to 21 (max)..
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(10.0f));

        // get my location address......

        myLocation();

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

    // marker information tab clicked...........

    googleMap.setOnInfoWindowClickListener(this);

}

// method my location
private void myLocation() {

    // TODO Auto-generated method stub

    // for logitude and latitude..........

    gps = new GPSTracker(MainActivity.this);

    // check if GPS enabled
    if (gps.canGetLocation()) {

        double latitude = gps.getLatitude();
        double longitude = gps.getLongitude();

        //double latitude = 40.71958;
        // double longitude = -74.09595;


        // Toast.makeText(getApplicationContext(),latitude
        // +"--"+longitude,Toast.LENGTH_SHORT).show();

        // for address..........
        Geocoder geocoder;
        List<Address> addresses = null;
        geocoder = new Geocoder(this, Locale.getDefault());
        try {
            addresses = geocoder.getFromLocation(latitude, longitude, 1);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String address = addresses.get(0).getAddressLine(0);
        String city = addresses.get(0).getAddressLine(1);
        String country = addresses.get(0).getAddressLine(2);

        Toast.makeText(getApplicationContext(),
                address + "" + city + "" + country, Toast.LENGTH_LONG)
                .show();

        Log.e("strite", address);
        Log.e("city", city);
        Log.e("country", country);
        // search string.....
        // String addr="Hotel "+address
        // +" "+city+" "+country;

        String addr = "Bar" + " " + city + " " + country;

        // call async task for load bars.....

        new GeocoderTask().execute(addr);

    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/**
 * function to load map. If map is not created it will create it for you
 * */
private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

@Override
protected void onResume() {
    super.onResume();
    initilizeMap();
}

// An AsyncTask class for accessing the GeoCoding Web Service
private class GeocoderTask extends AsyncTask<String, Void, List<Address>> {

    @Override
    protected List<Address> doInBackground(String... locationName) {
        // Creating an instance of Geocoder class
        // Geocoder transforming a street address or other description of a
        // location
        // into a (latitude, longitude) coordinate.
        Geocoder geocoder = new Geocoder(getBaseContext());
        List<Address> addresses = null;

        try {
            // Getting a maximum of 10 Address that matches the input text
            addresses = geocoder.getFromLocationName(locationName[0], 10);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return addresses;
    }

    @Override
    protected void onPostExecute(List<Address> addresses) {

        if (addresses == null || addresses.size() == 0) {
            Toast.makeText(getBaseContext(), "No Bar found",
                    Toast.LENGTH_SHORT).show();
        }

        // Clears all the existing markers on the map
        googleMap.clear();

        // Adding Markers on Google Map for each matching address
        for (int i = 0; i < addresses.size(); i++) {

            // address Strings describing a location
            adrs = (Address) addresses.get(i);

            // Creating an instance of GeoPoint, to display in Google Map
            // latLng class representing a pair of latitude and longitude
            // coordinates,

            latLng = new LatLng(adrs.getLatitude(), adrs.getLongitude());

            // latLng = new LatLng(40.71958,-74.09595);

            String addressText = String.format("%s, %s", adrs
                    .getMaxAddressLineIndex() > 0 ? adrs.getAddressLine(0)
                    : "", adrs.getCountryName());

            // markerOptions to add property to marker

            markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.title(adrs.getAddressLine(0));
            markerOptions.snippet(adrs.getAddressLine(1) + ", "
                    + adrs.getAddressLine(2) + ", "
                    + adrs.getPhone());

            /*
             * getAddressLine(0) location name .
             * getAddressLine(1) local address .
             * getAddressLine(2) city,state .
             * getAddressLine(3) country .
             */
            googleMap.addMarker(markerOptions);

            // Locate the first location
            if (i == 0)
                googleMap.animateCamera(CameraUpdateFactory
                        .newLatLng(latLng));
        }
        // end of loop.....
    }
}

// on marker info tab click..
@Override
public void onInfoWindowClick(Marker marker) {

    Toast.makeText(this, marker.getTitle() + "--" + marker.getSnippet(),
            Toast.LENGTH_LONG).show();

}
//谷歌地图
私人谷歌地图谷歌地图;
标记选项标记选项;
LatLng LatLng;
全球定位系统;
解决ADR问题;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
试一试{
//装载图
initilizeMap();
//我的位置。。。
googleMap.setMyLocationEnabled(true);
//从2(最小)到21(最大)的房间设置。。
googleMap.animateCamera(CameraUpdateFactory.zoomTo(10.0f));
//获取我的位置地址。。。。。。
myLocation();
}捕获(例外e){
e、 printStackTrace();
}
//已单击标记信息选项卡。。。。。。。。。。。
setOnInfoWindowClickListener(这个);
}
//方法我的位置
私有位置(){
//TODO自动生成的方法存根
//对于逻辑度和纬度。。。。。。。。。。
gps=新的GP斯特拉克(MainActivity.this);
//检查是否启用了GPS
if(gps.canGetLocation()){
双纬度=gps.getLatitude();
double longitude=gps.getLongitude();
//双纬度=40.71958;
//双经度=-74.09595;
//Toast.makeText(getApplicationContext(),latitude)
//+“--”+经度,Toast.LENGTH_SHORT.show();
//地址。。。。。。。。。。
地理编码器;
列表地址=空;
geocoder=新的geocoder(这个,Locale.getDefault());
试一试{
地址=地理编码器.getFromLocation(纬度,经度,1);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
字符串地址=地址.get(0).getAddressLine(0);
字符串city=addresses.get(0).getAddressLine(1);
字符串country=addresses.get(0).getAddressLine(2);
Toast.makeText(getApplicationContext(),
地址+“”+城市+“”+国家,祝酒词长度(长)
.show();
Log.e(“strite”,地址);
Log.e(“城市”,城市);
Log.e(“国家”,国家);
//搜索字符串。。。。。
//String addr=“Hotel”+地址
//+“”+城市+“”+国家;
字符串addr=“Bar”+“”+城市+“”+国家;
//调用加载条的异步任务。。。。。
新的GeocoderTask().execute(addr);
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
/**
*函数加载映射。如果未创建映射,它将为您创建映射
* */
私有void initilizeMap(){
if(googleMap==null){
googleMap=((MapFragment)getFragmentManager().findFragmentById(
R.id.map)).getMap();
//检查是否成功创建映射
if(googleMap==null){
Toast.makeText(getApplicationContext(),
“抱歉!无法创建地图”,Toast.LENGTH\u SHORT)
.show();
}
}
}
@凌驾
受保护的void onResume(){
super.onResume();
initilizeMap();
}
//用于访问地理编码Web服务的AsyncTask类
私有类GeocoderTask扩展异步任务{
@凌驾
受保护列表doInBackground(字符串…位置名称){
//创建Geocoder类的实例
//地理编码器,用于转换街道地址或其他城市描述
//位置
//转换为(纬度、经度)坐标。
Geocoder Geocoder=新的Geocoder(getBaseContext());
列表地址=空;
试一试{
//获取最多10个与输入文本匹配的地址
addresses=geocoder.getFromLocationName(locationName[0],10);
}捕获(IOE异常){
e、 printStackTrace();
}
返回地址;
}
@凌驾
受保护的void onPostExecute(列表地址){
if(addresses==null | | addresses.size()==0){
Toast.makeText(getBaseContext(),“未找到任何条”,
吐司。长度(短)。show();
}
//清除地图上的所有现有标记
googleMap.clear();
//在谷歌地图上为每个匹配地址添加标记
对于(int i=0;i0?adrs.getAddressLine(0)
:“”,adrs.getCountryName());
//marker将特性添加到标记的选项
markerOptions=新的markerOptions();
标记选项位置(板条);
markerOptions.title(adrs.getAddressLine(0));
markerOptions.snippet(adrs.getAddressLine(1)+“
+adrs.getAddressLine(2)+“
+adrs.getPhone());
/*
*getAddressLine(0)位置名称。
*getAddressLine(1)本地地址。
*getAddressLine(2)城市,州。
*getAddressLine(3)国家/地区。
*/
googleMap.addMarker(markerOptions);
//找到第一个位置
如果(i==0)
googleMap.animateCamera(CameraUpdateFactory
public void onInfoWindowClick(Marker marker) {

String[] str2 = marker.getSnippet().split(",");
String Addressline1=str2[0]; //Addressline 1
String Addressline2=str2[1]; //Addressline 2
String phone=str2[2]; //Phone

Toast.makeText(this, marker.getTitle() + "--" + marker.getSnippet()+"-- "+phone,
        Toast.LENGTH_LONG).show();
}