Google地图在第二个活动中无法打开 [英] Google maps fails to open in second activity
问题描述
我正在申请,遇到了问题.
我为Google Maps单独开发了一个应用程序,它运行完美,并且我制作了第二个具有Listview的应用程序,然后单击ListView中的项目,另一个活动开始,其中带有不同标记的Google Maps打开.
因此,在单击列表视图中的单独对象后,我设法使另一个活动运行,因此我按照与我在Google Maps应用程序中相同的原则修改了.xml和.java文件,但不成功.
I'm making an application and ran into a problem.
I made separately app for google maps and it worked perfect, and I made second app in which I have listview, and by clicking on item in listview, another activity starts where google maps with different marks opens.
So I manage to get another activity running after clicking on separate objects in listview, so I modified that objects .xml and .java file on same principle as I did in my google maps app but somehow it doesn't works.
Main_Activity
package com.example.e_idem;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ListActivity {
String [] usluga = {
"Frizerski salon",
"Kafić",
"Vodoinstalater",
"Bravar",
"Ljekarna",
"Pekara",
"Autoservis",
"Dućan",
"Knjižnica",
"Papirnica",
"Željezara",
"Smartshop",
"Servis bicikla"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Odaberite uslugu koju tražite.")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
TextView messageView = (TextView)alert.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usluga));
}
public void onListItemClick(ListView parent, View view, int position,long id)
{
Toast.makeText(this, "Odabrali ste uslugu : "+usluga[position], Toast.LENGTH_LONG).show();
switch( position )
{
case 0: Intent activity_frizerski_salon = new Intent(this, FrizerskiSalon.class);
startActivity(activity_frizerski_salon);
break;
case 1: Intent activity_kafic = new Intent(this, Kafic.class);
startActivity(activity_kafic);
break;
case 2: Intent activity_vodoinstalater= new Intent(this, Vodoinstalater.class);
startActivity(activity_vodoinstalater);
break;
}
}
}
我在Main_Activity中调用的活动是单击列表视图中的对象
package com.example.e_idem;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
public class FrizerskiSalon extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frizerski_salon);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.fmap)).getMap();
LatLng vz = new LatLng(46.305746, 16.336606);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(vz, 13));
map.addMarker(new MarkerOptions()
.title("Varaždin")
.snippet("Barokni grad")
.position(vz));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.300274, 16.330769)));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.306274, 16.300769)));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.306974, 16.303169)));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.302874, 16.400710)));
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.e_idem"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<permission
android:name="com.example.e_idem.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.e_idem.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/house_flag"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.e_idem.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.e_idem.FrizerskiSalon"
android:label="@string/activity_frizerski_salon" >
</activity>
<activity
android:name="com.example.e_idem.Kafic"
android:label="@string/activity_kafic" >
</activity>
<activity
android:name="com.example.e_idem.Vodoinstalater"
android:label="@string/activity_vodoinstalater" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCKxxxxxxxxxxxxxxxxxxVfSY_9zxmU"/>
</application>
</manifest>
还有我的LogCat http://paste.strictfp.com/39582
And my LogCat http://paste.strictfp.com/39582
推荐答案
您的清单文件中需要2个元数据条目:
you need 2 meta-data entries in your manifest file:
1)地图键
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCKxxxxxxxxxxxxxxxxxxVfSY_9zxmU"/>
2)Google Play服务版本
2) google play services version
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
您错过了第二个
这篇关于Google地图在第二个活动中无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!