显示在Android设备磨损谷歌地图 [英] showing google maps on android wear devices

查看:127
本文介绍了显示在Android设备磨损谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个应用程序来显示ATM机在您的区域。它可以在我的Andr​​oid手机,但是当我尝试启动它在我的Andr​​oid穿戴式手表崩溃。随着错误二进制XML文件中的行#2错误充气类片段任何帮助是非常AP preciated。

下面是我的xml code

 < XML版本=1.0编码=UTF-8&GT?;
<片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:ID =@ + ID /图
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  类=com.google.android.gms.maps.MapFragment/>
 

和我的活动:

 公共类MainActivity延伸活动{

    私人最终字符串变量=的getClass()getSimpleName()。
    私人GoogleMap的MMAP;
    私有String []的地方;
    私人LocationManager locationManager;
    私人的位置禄;
    共享preferences SP;
    静态字符串距离;
    公共静态最后弦乐preF =我的preFS;
    公共静态最后弦乐距离=距离;

    @覆盖
    公共无效onResume(){
        super.onResume();
        SP = this.getShared preferences(preF,Context.MODE_PRIVATE);
        距离= sp.getString(距离,1000);

        MMAP =((MapFragment)getFragmentManager()。findFragmentById(R.id.map))
                .getMap();
        当前位置();
        地方=新的String [1];
        地方[0] =提款机;
        mMap.setMyLocationEnabled(真正的);

    }

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

    }

    私有类GetPlaces扩展的AsyncTask<虚空,虚空,ArrayList的<地方>> {

        私人ProgressDialog对话框;
        私人上下文的背景下;
        私人字符串的地方;
        私人双经度;
        私人双重纬度;

        公共GetPlaces(上下文的背景下,字符串的地方){
            this.context =背景;
            this.places =场所;
        }

        @覆盖
        保护无效onPostExecute(ArrayList中<地方>的结果){
            super.onPostExecute(结果);
            LocationManager LM =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
            位置位置= LM
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
            经度= location.getLongitude();
            纬度= location.getLatitude();
            如果(dialog.isShowing()){
                dialog.dismiss();
            }
            的for(int i = 0; I< result.size();我++){
                mMap.addMarker(新MarkerOptions()
                        .title伪(result.get(ⅰ).getName())
                        。位置(
                                新的经纬度(result.get(我).getLatitude(),结果
                                        获得(一).getLongitude()))
                        .icon(BitmapDesc​​riptorFactory
                                .fromResource(R.drawable.pin))
                        是.snippet(result.get(ⅰ).getVicinity()));
            }
            CameraPosition cameraPosition =新CameraPosition.Builder()
                    .TARGET(新经纬度(纬度,经度))//设置地图的中心
                    // 山顶风光
                    .zoom(14)//设置缩放
                    .tilt(30)//摄像机的倾斜设置为30度
                    。建立(); //创建从制造商一个CameraPosition
            mMap.animateCamera(CameraUpdateFactory
                    .newCameraPosition(cameraPosition));
        }



        @覆盖
        受保护的ArrayList<地方> doInBackground(虚空......为arg0){
            PlacesService服务=新PlacesService(
                    XXXXXXXXXXXXX);
            ArrayList的<地方> findPlaces = service.findPlaces(loc.getLatitude(),
                    loc.getLongitude(),位​​置的距离);

            的for(int i = 0; I< findPlaces.size();我++){

                放置placeDetail = findPlaces.get(ⅰ);
                Log.e(TAG,地方:+ placeDetail.getName());
            }
            返回findPlaces;
        }

    }



    私人无效currentLocation(){
        locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);

        字符串商= locationManager
                .getBestProvider(新标准(),FALSE);

        位置位置= locationManager.getLastKnownLocation(供应商);

        如果(位置== NULL){
            locationManager.requestLocationUpdates(提供商,0,0,侦听);
        } 其他 {
            LOC =位置;
            新GetPlaces(MainActivity.this,地方[0] .toLowerCase()代替(
                    -, _))。执行();
            Log.e(TAG的位置:+位置);
        }

    }

    私人LocationListener的监听器=新LocationListener的(){

        @覆盖
        公共无效onStatusChanged(字符串商,INT地位,捆绑演员){

        }

        @覆盖
        公共无效onProviderEnabled(字符串提供商){

        }

        @覆盖
        公共无效onProviderDisabled(字符串提供商){

        }

        @覆盖
        公共无效onLocationChanged(位置定位){
            Log.e(TAG,位置更新:+位置);
            LOC =位置;
            locationManager.removeUpdates(听众);
        }
    };


}
 

解决方案

不幸的是, MapFragment GoogleMap的(沿与完全的谷歌地图Android的API的)是目前不支持Android Wear设备。

I have developed an app to show ATM machines in your area. It works on my android phone but when I try to launch it on my android wearable watch it crashes. With the error "Binary XML File line #2 Error inflating class fragment" Any help is much appreciated.

Here is my xml code

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.MapFragment"/>

and my activity:

public class MainActivity extends Activity {

    private final String TAG = getClass().getSimpleName();
    private GoogleMap mMap;
    private String[] places;
    private LocationManager locationManager;
    private Location loc;
    SharedPreferences sp;
    static String distance;
    public static final String PREF = "MyPrefs";
    public static final String DISTANCE = "distance";

    @Override
    public void onResume() {
        super.onResume();
        sp = this.getSharedPreferences(PREF, Context.MODE_PRIVATE);
        distance = sp.getString(DISTANCE, "1000");

        mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();
        currentLocation();
        places=new String[1];
        places[0]="ATM";
        mMap.setMyLocationEnabled(true);

    }

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

    }

    private class GetPlaces extends AsyncTask<Void, Void, ArrayList<Place>> {

        private ProgressDialog dialog;
        private Context context;
        private String places;
        private double longitude;
        private double latitude;

        public GetPlaces(Context context, String places) {
            this.context = context;
            this.places = places;
        }

        @Override
        protected void onPostExecute(ArrayList<Place> result) {
            super.onPostExecute(result);
            LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Location location = lm
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
            longitude = location.getLongitude();
            latitude = location.getLatitude();
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
            for (int i = 0; i < result.size(); i++) {
                mMap.addMarker(new MarkerOptions()
                        .title(result.get(i).getName())
                        .position(
                                new LatLng(result.get(i).getLatitude(), result
                                        .get(i).getLongitude()))
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.pin))
                        .snippet(result.get(i).getVicinity()));
            }
            CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(new LatLng(latitude, longitude)) // Sets the center of the map to
                    // Mountain View
                    .zoom(14) // Sets the zoom
                    .tilt(30) // Sets the tilt of the camera to 30 degrees
                    .build(); // Creates a CameraPosition from the builder
            mMap.animateCamera(CameraUpdateFactory
                    .newCameraPosition(cameraPosition));
        }



        @Override
        protected ArrayList<Place> doInBackground(Void... arg0) {
            PlacesService service = new PlacesService(
                    "xxxxxxxxxxxxx");
            ArrayList<Place> findPlaces = service.findPlaces(loc.getLatitude(), 
                    loc.getLongitude(), places, distance); 

            for (int i = 0; i < findPlaces.size(); i++) {

                Place placeDetail = findPlaces.get(i);
                Log.e(TAG, "places : " + placeDetail.getName());
            }
            return findPlaces;
        }

    }



    private void currentLocation() {
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        String provider = locationManager
                .getBestProvider(new Criteria(), false);

        Location location = locationManager.getLastKnownLocation(provider);

        if (location == null) {
            locationManager.requestLocationUpdates(provider, 0, 0, listener);
        } else {
            loc = location;
            new GetPlaces(MainActivity.this, places[0].toLowerCase().replace(
                    "-", "_")).execute();
            Log.e(TAG, "location : " + location);
        }

    }

    private LocationListener listener = new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {

        }

        @Override
        public void onProviderEnabled(String provider) {

        }

        @Override
        public void onProviderDisabled(String provider) {

        }

        @Override
        public void onLocationChanged(Location location) {
            Log.e(TAG, "location update : " + location);
            loc = location;
            locationManager.removeUpdates(listener);
        }
    };


}

解决方案

Unfortunately, MapFragment and GoogleMap (along with the entirely of the Google Maps Android API) is currently not supported on Android Wear devices.

这篇关于显示在Android设备磨损谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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