我正在尝试将一个带有此数据lat, long, route, direction
的contanis 3元素的arrayList从我的GETLLRD
类传递到Map
活动,以显示Google地图中的位置但我是面临谷歌地图加载位置太慢的问题。有谁看到有问题的地方?
我感谢任何帮助。
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);
}
}
}
}
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"/>