【问题标题】:Map not showing anything地图不显示任何东西
【发布时间】:2013-12-16 05:50:28
【问题描述】:
import java.util.ArrayList;
import java.util.List;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

public class Map extends FragmentActivity {

Cursor c;
MyDataBase mdb;
ArrayList<String> stop;




GoogleMap gmaps;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
    mdb=new MyDataBase(this);
    mdb.open();
    double[] latitude=new double[97];
    double[] longitude=new double[97];
    stop=new ArrayList<String>();
    Intent intent=getIntent();
    stop=intent.getStringArrayListExtra("stopslist");
    for(int i=0;i<stop.size();i++)
    {
    c=mdb.getStops(stop.get(i));
    while(c.moveToNext())
    {
        latitude[i]=c.getDouble(2);
        longitude[i]=c.getDouble(3);
        //Toast.makeText(getApplicationContext(),latitude[i]+"  "+longitude[i], 1).show();  

    }
    }

    SupportMapFragment map = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    gmaps=map.getMap();
    gmaps.setMyLocationEnabled(true);
    LatLng ll=new LatLng(latitude[0], longitude[0]);
   gmaps.moveCamera(CameraUpdateFactory.newLatLng(ll));
   gmaps.animateCamera(CameraUpdateFactory.zoomTo(12));

   for(int i=0;i<stop.size();i++)
   { 
       ll=new LatLng(latitude[i],longitude[i]);
       gmaps.addMarker(new MarkerOptions()
       .title(stop.get(i))
       .snippet(stop.get(i)+" "+"Metro Station")
       .position(ll));
   }

}

}

编辑:

这是我编写的用于在地图上固定标记的代码,但是当我按下按钮时,它会转到谷歌地图并保持空白。有人可以告诉这里有什么问题吗?

【问题讨论】:

标签: java android google-maps maps


【解决方案1】:

只需将 google play 服务库添加到您的项目中即可。

转到你的项目 -> 属性 -> android -> 在项目构建目标部分 -> 检查 google api

【讨论】:

    【解决方案2】:

    在你的清单中检查一下:

    <uses-library
            android:name="com.google.android.maps" />
    

    【讨论】:

    • @Raghunandan 为什么不呢?
    • @shylendra developers.google.com/maps/documentation/android/…。看看这个你就知道了
    • @Akshat 您是否已将 google play 库添加到您的项目中?并且位于同一工作区
    • @Akshat which api are you using api 1 is deprecated switch to api v2 and it looks like you are using api v1.
    【解决方案3】:

    下载相应的android-google-maps-api.jarhere以避免错误并检查清单

    <uses-library
            android:name="com.google.android.maps" />
    

    【讨论】:

      【解决方案4】:

      我不知道为什么这里的人试图混淆你,让你使用一个已经被弃用近一年的 API,但这里的答案是错误的。

      这行代码就不用加了:

      <uses-library android:name="com.google.android.maps" />
      

      因为这行代码属于之前的API v1API v2 的配置非常不同。 实际上,您提供的代码是API V2 的代码,所以您走在正确的轨道上。

      请查看这 2 篇博文以确保您已正确提交所有步骤:

      Google Maps API V2 key

      和:

      Google Maps API V2

      如果这对您没有帮助,请使用您的 XML 清单文件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多