Android 谷歌地图加载位置太慢
我试图将一个包含3个元素的数组列表从我的Android 谷歌地图加载位置太慢,android,google-maps,Android,Google Maps,我试图将一个包含3个元素的数组列表从我的GETLLRD类传递到Map活动,以在谷歌地图中显示位置,其中包含的数据lat、long、route、direction。有人看到哪里出了问题吗 谢谢你的帮助 GetLLRD类: Intent intent1 = new Intent(this, Map.class); intent1.putExtra("list_data", data);
GETLLRD
类传递到Map
活动,以在谷歌地图中显示位置,其中包含的数据lat、long、route、direction
。有人看到哪里出了问题吗
谢谢你的帮助
GetLLRD类:
Intent intent1 = new Intent(this, Map.class);
intent1.putExtra("list_data", data);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent1);
public class Map extends FragmentActivity implements OnMapReadyCallback {
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
private boolean initMap() {
if (map == null) {
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = mapFrag.getMap();
}
return (map != null);
}
private void gotoLocation(double lat, double lng, String route_direct) {
final float zoom = 11;
LatLng ll = new LatLng(lat, lng);
MarkerOptions markerOpt = new MarkerOptions().title(route_direct)
.position(ll).visible(true);
Marker marker = map.addMarker(markerOpt);
marker.showInfoWindow();
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
map.moveCamera(update);
System.out.println("test from Map end gotoLocationp(): ");
}
@Override
public void onMapReady(GoogleMap arg0) {
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@SuppressWarnings("unchecked")
ArrayList<ItemDTO> list = (ArrayList<ItemDTO>) intent
.getSerializableExtra("list_data");
for (ItemDTO itemDTO : list) {
double latitude = itemDTO.getLatitude();
double longitude = itemDTO.getLongitude();
int route1 = itemDTO.getRoute();
String route = Integer.toString(route1);
String direction = itemDTO.getDirection();
String route_dirc = route + ", " + direction;
if (initMap()) {
gotoLocation(latitude, longitude, route_dirc);
}
}
}
}
地图活动:
Intent intent1 = new Intent(this, Map.class);
intent1.putExtra("list_data", data);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent1);
public class Map extends FragmentActivity implements OnMapReadyCallback {
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
private boolean initMap() {
if (map == null) {
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = mapFrag.getMap();
}
return (map != null);
}
private void gotoLocation(double lat, double lng, String route_direct) {
final float zoom = 11;
LatLng ll = new LatLng(lat, lng);
MarkerOptions markerOpt = new MarkerOptions().title(route_direct)
.position(ll).visible(true);
Marker marker = map.addMarker(markerOpt);
marker.showInfoWindow();
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
map.moveCamera(update);
System.out.println("test from Map end gotoLocationp(): ");
}
@Override
public void onMapReady(GoogleMap arg0) {
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@SuppressWarnings("unchecked")
ArrayList<ItemDTO> list = (ArrayList<ItemDTO>) intent
.getSerializableExtra("list_data");
for (ItemDTO itemDTO : list) {
double latitude = itemDTO.getLatitude();
double longitude = itemDTO.getLongitude();
int route1 = itemDTO.getRoute();
String route = Integer.toString(route1);
String direction = itemDTO.getDirection();
String route_dirc = route + ", " + direction;
if (initMap()) {
gotoLocation(latitude, longitude, route_dirc);
}
}
}
}
公共类映射扩展了FragmentActivity在MapreadyCallback上的实现{
谷歌地图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
}
私有布尔initMap(){
if(map==null){
SupportMapFragment MapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
map=mapFrag.getMap();
}
返回(map!=null);
}
专用空位定位(双lat、双lng、管柱直接路由){
最终浮点缩放=11;
LatLng ll=新LatLng(lat,lng);
MarkerOptions markerOpt=新的MarkerOptions().标题(路线\直达)
.位置(ll).可见(真实);
Marker-Marker=map.addMarker(markerOpt);
marker.showInfoWindow();
CameraUpdate update=CameraUpdateFactory.newLatLngZoom(ll,缩放);
地图。移动摄像机(更新);
println(“从映射端测试gotoLocationp():”;
}
@凌驾
mapready上的公共无效(谷歌地图arg0){
}
@凌驾
受保护的void onNewIntent(意图){
super.onNewIntent(意向);
@抑制警告(“未选中”)
ArrayList list=(ArrayList)intent
.getSerializableExtra(“列表数据”);
for(ItemDTO ItemDTO:list){
双纬度=itemDTO.getLatitude();
double longitude=itemDTO.getLongitude();
int route1=itemDTO.getRoute();
字符串route=Integer.toString(route1);
字符串方向=itemDTO.getDirection();
字符串route_dirc=route+“,”+方向;
if(initMap()){
地理位置(纬度、经度、路线);
}
}
}
}
map.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MainActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>