【发布时间】: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));
}
}
}
编辑:
这是我编写的用于在地图上固定标记的代码,但是当我按下按钮时,它会转到谷歌地图并保持空白。有人可以告诉这里有什么问题吗?
【问题讨论】:
-
你在你的android项目中引用了google play services library项目吗?
-
是的,我做到了。但这些问题仍然存在。
-
你是怎么做到的。并使用 map api v2 检查这个developers.google.com/maps/documentation/android/… 对吗?
标签: java android google-maps maps