谷歌地图v2安卓标记赢了不显示

时间:2015-01-16 08:47:06

标签: android eclipse google-maps-markers google-maps-android-api-2

你好,我是android开发的新手。我试图在我的地图上添加一个简单的标记,但它不会显示。我正在使用Eclipse Luna。我不确定我是否做得很好,但我确实没错!我正在使用模拟器运行。在我写这篇文章之前,我搜索了几天。任何帮助都会很受欢迎! PS.Thanks提前。

MainActivity

      import com.google.android.gms.maps.*;
        import com.google.android.gms.maps.model.*;
        import android.app.Activity;
        import android.os.Bundle;

        public class MainActivity extends Activity implements OnMapReadyCallback {

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

                MapFragment mapFragment = (MapFragment) getFragmentManager()
                        .findFragmentById(R.id.map);
                mapFragment.getMapAsync(this);

            }

            @Override
            public void onMapReady(GoogleMap map) {
                LatLng sydney = new LatLng(-33.867, 151.206);

                map.setMyLocationEnabled(true);
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));

                map.addMarker(new MarkerOptions()
                        .title("Sydney")
                        .snippet("The most populous city in Australia.")
                        .position(sydney));
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                        new LatLng(-18.142, 178.431), 2));

                // Other supported types include: MAP_TYPE_NORMAL,
                // MAP_TYPE_TERRAIN, MAP_TYPE_HYBRID and MAP_TYPE_NONE
                map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            }
        }

**activity_main.xml**

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >



      <fragment
          android:id="@+id/map"
          android:name="com.google.android.gms.maps.MapFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/>

    </RelativeLayout>

**AndroidManiFest.xml**

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xml>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.stavros.map"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
   <!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature android:glEsVersion="0x00020000"
              android:required="true" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
        <meta-data android:name="com.google.android.maps.v2.API_KEY"
                   android:value="AIzaSyDQpV-9M************"/>
        <uses-library android:name="com.google.android.maps" /> 
        <meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version"/>
        <activity
            android:name=".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>

    </application>

</manifest>

3 个答案:

答案 0 :(得分:0)

试试这个

public class MainActivity extends FragmentActivity implements LocationListener{
private GoogleMap googlemap;

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

    final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
    Marker melbourne = googlemap.addMarker(new MarkerOptions()
    .position(MELBOURNE)
    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
}

private void initMap() {
    // TODO Auto-generated method stub
    try {
        if (googlemap== null) {
            googlemap = ((SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map)).getMap();
        }
        googlemap.getUiSettings().setZoomControlsEnabled(false);
    } catch (Exception e) {
    e.printStackTrace();
    }
}

@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub

}
}

答案 1 :(得分:0)

private void drawMarker(Location location) throws Exception{
            map.clear();

//获取位置

 LatLng currentPosition = new LatLng(location.getLatitude(),location.getLongitude());

LatLng currentPosition = new LatLng(-37.813, 144.962);

//将标记添加到currentPosition

      Marker   markerEnd = map.addMarker(new MarkerOptions()
        .position(currentPosition)
        .snippet(address(location.getLatitude(), location.getLongitude()))
       .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.ic_marker))));
}

答案 2 :(得分:0)

  This is my full error log  

01-16 05:38:17.610: E/logwrapper(909): executing /system/bin/e2fsck failed: No such file or directory
    01-16 05:38:17.650: E/logwrapper(915): executing /system/bin/e2fsck failed: No such file or directory
    01-16 05:38:18.480: E/SurfaceFlinger(925): hwcomposer module not found
    01-16 05:38:18.680: E/AudioFlinger(928): int android::load_audio_interface(const char*, audio_hw_device_t**) couldn't load audio hw module audio.r_submix (No such file or directory)
    01-16 05:38:19.040: E/SurfaceFlinger(925): ro.sf.lcd_density must be defined as a build property
    01-16 05:38:21.200: E/memtrack(926): Couldn't load memtrack module (No such file or directory)
    01-16 05:38:21.200: E/android.os.Debug(926): failed to load memtrack module: -2
    01-16 05:38:21.820: E/logwrapper(1190): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:21.840: E/logwrapper(1191): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:21.920: E/logwrapper(1196): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:22.520: E/EmojiFactory_jni(926): Failed to load libemoji.so: dlopen failed: library "libemoji.so" not found
    01-16 05:38:22.720: E/BandwidthController(922): runIptablesCmd(): res=1 status=256 failed /system/bin/iptables -A bw_INPUT -m owner --socket-exists
    01-16 05:38:22.740: E/BandwidthController(922): runIptablesCmd(): res=1 status=256 failed /system/bin/ip6tables -A bw_INPUT -m owner --socket-exists
    01-16 05:38:22.830: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_OUTPUT -m mark --mark 1 -j RETURN 
    01-16 05:38:22.830: E/Netd(922): exec() res=0, status=256 for /system/bin/ip6tables -t mangle -A st_mangle_OUTPUT -m mark --mark 1 -j RETURN 
    01-16 05:38:22.850: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_OUTPUT -m owner --uid-owner vpn -j RETURN 
    01-16 05:38:22.850: E/Netd(922): exec() res=0, status=256 for /system/bin/ip6tables -t mangle -A st_mangle_OUTPUT -m owner --uid-owner vpn -j RETURN 
    01-16 05:38:24.490: E/(926): Failed to connect to host (QemuPipeStream)!!!
    01-16 05:38:24.490: E/EGL_emulation(926): Failed to establish connection with the host
    01-16 05:38:24.530: E/EGL_emulation(926): Failed to establish connection with the host
    01-16 05:38:24.530: E/(926): Failed to connect to host (QemuPipeStream)!!!
    01-16 05:38:24.530: E/EGL_emulation(926): Failed to establish connection with the host
    01-16 05:38:24.530: E/EGL_emulation(926): Failed to establish connection with the host
    01-16 05:38:24.640: E/PowerManagerService-JNI(1264): Couldn't load power module (No such file or directory)
    01-16 05:38:24.690: E/SurfaceFlinger(925): ro.sf.lcd_density must be defined as a build property
    01-16 05:38:26.760: E/ConsumerIrService(1264): Can't open consumer IR HW Module, error: -2
    01-16 05:38:26.760: E/libsuspend(1264): Error opening /sys/power/autosleep: No such file or directory
    01-16 05:38:26.840: E/EventHub(1264): could not get driver version for /dev/input/mouse0, Not a typewriter
    01-16 05:38:26.840: E/EventHub(1264): could not get driver version for /dev/input/mice, Not a typewriter
    01-16 05:38:26.950: E/MobileDataStateTracker(1264): default: Ignoring feature request because could not acquire PhoneService
    01-16 05:38:26.950: E/MobileDataStateTracker(1264): default: Could not enable APN type "default"
    01-16 05:38:27.440: E/FlpHardwareProvider(1264): Error hw_get_module 'flp': -2
    01-16 05:38:27.440: E/FlpHardwareProvider(1264): Error hw_get_module 'flp': -2
    01-16 05:38:27.550: E/SoundPool(1326): error loading /system/media/audio/ui/Lock.ogg
    01-16 05:38:27.550: E/SoundPool(1326): error loading /system/media/audio/ui/Unlock.ogg
    01-16 05:38:30.340: E/BluetoothAdapter(1396): Bluetooth binder is null
    01-16 05:38:31.580: E/gralloc_goldfish(925): gralloc_alloc: Mismatched usage flags: 480 x 800, usage b33
    01-16 05:38:31.580: E/(925): GraphicBufferAlloc::createGraphicBuffer(w=480, h=800) failed (Invalid argument), handle=0x0
    01-16 05:38:31.580: E/BufferQueue(925): [ScreenshotSurface] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
    01-16 05:38:31.790: E/GCoreFlp(1365): Bound FusedProviderService with LocationManager
    01-16 05:38:31.850: E/GCoreFlp(1365): Bound FusedProviderService with LocationManager
    01-16 05:38:31.860: E/BluetoothAdapter(1326): Bluetooth binder is null
    01-16 05:38:32.740: E/BluetoothAdapter(1569): Bluetooth binder is null
    01-16 05:38:33.460: E/dalvikvm(1594): Could not find class 'android.telecom.TelecomManager', referenced from method com.google.android.gms.wearable.service.o.e
    01-16 05:38:33.890: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.2/32 -j MARK --set-mark 1 
    01-16 05:38:33.890: E/logwrapper(1644): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:33.890: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '12 interface fwmark exempt add 10.0.2.2/32' failed with '400 12 Failed to add exemption rule (File exists)'
    01-16 05:38:34.060: E/BluetoothAdapter(1365): Bluetooth binder is null
    01-16 05:38:34.180: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.3/32 -j MARK --set-mark 1 
    01-16 05:38:34.180: E/logwrapper(1649): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:34.180: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '14 interface fwmark exempt add 10.0.2.3/32' failed with '400 14 Failed to add exemption rule (File exists)'
    01-16 05:38:34.190: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.2/32 -j MARK --set-mark 1 
    01-16 05:38:34.190: E/logwrapper(1651): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:34.230: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '16 interface fwmark exempt add 10.0.2.2/32' failed with '400 16 Failed to add exemption rule (File exists)'
    01-16 05:38:34.240: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.4/32 -j MARK --set-mark 1 
    01-16 05:38:34.240: E/logwrapper(1653): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:34.240: E/logwrapper(1654): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:34.240: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '18 interface fwmark exempt add 10.0.2.4/32' failed with '400 18 Failed to add exemption rule (File exists)'
    01-16 05:38:34.260: E/copresGcore(1365): WifiMedium: Wifi is not supported!!
    01-16 05:38:34.310: E/SecondaryTablController(922): ip route add failed: /system/bin/ip route add 10.0.2.2/32 via 0.0.0.0 dev eth0 table 60
    01-16 05:38:34.340: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '19 interface route add eth0 secondary 10.0.2.2 32 0.0.0.0' failed with '400 19 ip route modification failed (No such device)'
    01-16 05:38:34.350: E/logwrapper(1659): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:34.380: E/SecondaryTablController(922): ip route add failed: /system/bin/ip route add 0.0.0.0/0 via 10.0.2.2 dev eth0 table 60
    01-16 05:38:34.490: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '20 interface route add eth0 secondary 0.0.0.0 0 10.0.2.2' failed with '400 20 ip route modification failed (No such device)'
    01-16 05:38:34.550: E/copresGcore(1365): ObfuscatedGaiaIdLookup: Could not load ObfuscatedGaiaIds: /data/data/com.google.android.gms/files/copresence_gaia_id: open failed: ENOENT (No such file or directory)
    01-16 05:38:34.730: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.2/32 -j MARK --set-mark 1 
    01-16 05:38:34.730: E/logwrapper(1669): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:34.780: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 74.125.71.139/32 -j MARK --set-mark 1 
    01-16 05:38:34.780: E/logwrapper(1671): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:34.780: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '22 interface fwmark exempt add 10.0.2.2/32' failed with '400 22 Failed to add exemption rule (File exists)'
    01-16 05:38:34.830: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '24 interface fwmark exempt add 74.125.71.139/32' failed with '400 24 Failed to add exemption rule (File exists)'
    01-16 05:38:35.190: E/copresGcore(1365): Couldn't load settings: /data/data/com.google.android.gms/files/copresence_settings: open failed: ENOENT (No such file or directory)
    01-16 05:38:35.410: E/BluetoothAdapter(1569): Bluetooth binder is null
    01-16 05:38:36.020: E/EGL_emulation(988): tid 1019: eglMakeCurrent(917): error 0x3001 (EGL_NOT_INITIALIZED)
    01-16 05:38:37.010: E/memtrack(1693): Couldn't load memtrack module (No such file or directory)
    01-16 05:38:37.010: E/android.os.Debug(1693): failed to load memtrack module: -2
    01-16 05:38:37.900: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.2/32 -j MARK --set-mark 1 
    01-16 05:38:37.900: E/logwrapper(1721): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:38.280: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '26 interface fwmark exempt add 10.0.2.2/32' failed with '400 26 Failed to add exemption rule (File exists)'
    01-16 05:38:38.320: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 74.125.71.101/32 -j MARK --set-mark 1 
    01-16 05:38:38.330: E/logwrapper(1723): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:38.330: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '28 interface fwmark exempt add 74.125.71.101/32' failed with '400 28 Failed to add exemption rule (File exists)'
    01-16 05:38:39.960: E/memtrack(1732): Couldn't load memtrack module (No such file or directory)
    01-16 05:38:39.960: E/android.os.Debug(1732): failed to load memtrack module: -2
    01-16 05:38:41.390: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.2/32 -j MARK --set-mark 1 
    01-16 05:38:41.390: E/logwrapper(1774): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:41.400: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '30 interface fwmark exempt add 10.0.2.2/32' failed with '400 30 Failed to add exemption rule (File exists)'
    01-16 05:38:41.470: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 74.125.71.113/32 -j MARK --set-mark 1 
    01-16 05:38:41.470: E/logwrapper(1776): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:41.470: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '32 interface fwmark exempt add 74.125.71.113/32' failed with '400 32 Failed to add exemption rule (File exists)'
    01-16 05:38:44.500: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.2/32 -j MARK --set-mark 1 
    01-16 05:38:44.500: E/Netd(922): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 74.125.71.138/32 -j MARK --set-mark 1 
    01-16 05:38:44.500: E/logwrapper(1783): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:44.500: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '34 interface fwmark exempt add 10.0.2.2/32' failed with '400 34 Failed to add exemption rule (File exists)'
    01-16 05:38:44.500: E/logwrapper(1781): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:44.510: E/ConnectivityService(1264): Exception trying to add a route: java.lang.IllegalStateException: command '36 interface fwmark exempt add 74.125.71.138/32' failed with '400 36 Failed to add exemption rule (File exists)'
    01-16 05:38:47.540: E/logwrapper(1786): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:47.570: E/SecondaryTablController(922): ip route del failed: /system/bin/ip route del 10.0.2.2/32 via 0.0.0.0 dev eth0 table 60
    01-16 05:38:47.570: E/logwrapper(1787): executing /system/bin/ip failed: No such file or directory
    01-16 05:38:47.570: E/SecondaryTablController(922): ip route del failed: /system/bin/ip route del 0.0.0.0/0 via 10.0.2.2 dev eth0 table 60
    01-16 05:38:48.410: E/AuthorizationBluetoothService(1447): Proximity feature is not enabled.
    01-16 05:38:48.420: E/AuthorizationBluetoothService(1447): Proximity feature is not enabled.
    01-16 05:38:48.500: E/AuthorizationBluetoothService(1447): Proximity feature is not enabled.
    01-16 05:38:48.730: E/BluetoothAdapter(1569): Bluetooth binder is null
    01-16 05:38:48.740: E/AuthorizationBluetoothService(1447): Proximity feature is not enabled.
    01-16 05:39:07.480: E/AuthorizationBluetoothService(1447): Proximity feature is not enabled.
    01-16 05:39:08.120: E/BluetoothAdapter(1569): Bluetooth binder is null
    01-16 05:39:28.311: E/StrictMode(1869): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
    01-16 05:39:28.311: E/StrictMode(1869): java.lang.Throwable: Explicit termination method 'release' not called
    01-16 05:39:28.311: E/StrictMode(1869):     at dalvik.system.CloseGuard.open(CloseGuard.java:184)
    01-16 05:39:28.311: E/StrictMode(1869):     at android.drm.DrmManagerClient.<init>(DrmManagerClient.java:258)
    01-16 05:39:28.311: E/StrictMode(1869):     at com.google.android.mms.pdu.PduPersister.<init>(PduPersister.java:288)
    01-16 05:39:28.311: E/StrictMode(1869):     at com.google.android.mms.pdu.PduPersister.getPduPersister(PduPersister.java:296)
    01-16 05:39:28.311: E/StrictMode(1869):     at com.android.mms.transaction.TransactionService.onNewIntent(TransactionService.java:224)
    01-16 05:39:28.311: E/StrictMode(1869):     at com.android.mms.transaction.TransactionService$ServiceHandler.handleMessage(TransactionService.java:621)
    01-16 05:39:28.311: E/StrictMode(1869):     at android.os.Handler.dispatchMessage(Handler.java:102)
    01-16 05:39:28.311: E/StrictMode(1869):     at android.os.Looper.loop(Looper.java:136)
    01-16 05:39:28.311: E/StrictMode(1869):     at android.os.HandlerThread.run(HandlerThread.java:61)