Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.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
Google Maps Android API V2使用标记显示当前位置(我在Google Android Maps API V2中的何处)_Android_Eclipse_Google Maps - Fatal编程技术网

Google Maps Android API V2使用标记显示当前位置(我在Google Android Maps API V2中的何处)

Google Maps Android API V2使用标记显示当前位置(我在Google Android Maps API V2中的何处),android,eclipse,google-maps,Android,Eclipse,Google Maps,我是android的初学者,我正在开发一个android应用程序,用于在谷歌地图上显示我的当前位置。但当我运行我的应用程序时,它会在模拟器和物理设备上显示一条消息“不幸停止”。 我正在附上我的密码。请看一下。 请帮助我…我无法解决这个问题 谢谢 MainActivity.java 包com.example.mapp import android.app.Dialog; import android.location.Location; import android.os.Bundle; impo

我是android的初学者,我正在开发一个android应用程序,用于在谷歌地图上显示我的当前位置。但当我运行我的应用程序时,它会在模拟器和物理设备上显示一条消息“不幸停止”。 我正在附上我的密码。请看一下。 请帮助我…我无法解决这个问题

谢谢

MainActivity.java

包com.example.mapp

import android.app.Dialog;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.TextView;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

public class MainActivity extends FragmentActivity implements OnMyLocationChangeListener {
GoogleMap googlemap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        int status=GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
        if(status!=ConnectionResult.SUCCESS)
        {
            int requestCode=10;
            Dialog dialog=GooglePlayServicesUtil.getErrorDialog(status,this, requestCode);
            dialog.show();
        }
        else
        {
            SupportMapFragment fm = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
                    googlemap=fm.getMap();
                    googlemap.setMyLocationEnabled(true);
                    googlemap.setOnMyLocationChangeListener(this);
        }
    }

@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;
}

@Override
public void onMyLocationChange(Location location) {

    TextView tvLocation=(TextView)findViewById(R.id.textview1);
    double latitude=location.getLatitude();
    double longitude=location.getLongitude();
    LatLng latLng=new LatLng(latitude,longitude);
    googlemap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    googlemap.animateCamera(CameraUpdateFactory.zoomTo(15));
    tvLocation.setText("Latitude:"+latitude+",Longitude:"+longitude);
}


}
AndroidManifest.xml


*活动\u main.xml*

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
        <fragment

        class="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/map"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/textview1"

       />

</RelativeLayout>

在应用程序标记中添加以下代码

<meta-data 
       android:name="com.google.android.gms.version" 
       android:value="@integer/google_play_services_version" />


我知道要显示您的当前位置,您必须使用真实设备发布堆栈跟踪。添加metag标记这不是答案。
<meta-data 
       android:name="com.google.android.gms.version" 
       android:value="@integer/google_play_services_version" />