我要做的是将一个位置列表传递给地图活动并将标记放在这些位置上.我已尝试在MainActivity中使用
public class MainActivity extends AppCompatActivity implements Parcelable {
ArrayList<Location> locs=new ArrayList<>();
...
locs.add(location);
...
Intent in = new Intent(context,MapsActivity.class);
in.putExtra("setlocations",locs);
startActivity(in);
...
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeList(locs);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在MapsActivity的onCreate()中
Bundle extras = getIntent().getExtras();
if(extras != null){
locs=(ArrayList<Location>)getIntent().getParcelableExtra("setlocations");
addMarkeratLocation();
}
Run Code Online (Sandbox Code Playgroud)
该addMarkeratLocation()方法使用locslist来使用for循环添加标记
public void addMarkeratLocation(){
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.mipmap.dott);
LatLng addpoint=new LatLng(0.0,0.0);
for(int i=0;i<locs.size();i++){
addpoint = new LatLng(locs.get(i).getLatitude(), locs.get(i).getLongitude());
mMap.addMarker(new MarkerOptions().position(addpoint).icon(icon));
}
mMap.moveCamera(CameraUpdateFactory.newLatLng(addpoint));
} …Run Code Online (Sandbox Code Playgroud) 我已经尝试过这个解决方案,但无法使其正常工作。我对 Angular2 完全陌生(不了解 AngularJS)。好吧,加载屏幕没有显示,我想我需要添加一些超时,以便它有一些时间显示,但我不知道在哪里以及如何显示。
应用程序组件.ts
import {Component} from '@angular/core';
import {
Router,
// import as RouterEvent to avoid confusion with the DOM Event
Event as RouterEvent,
NavigationStart,
NavigationEnd,
NavigationCancel,
NavigationError
} from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./loadingCSS.css']
})
export class AppComponent {
// Sets initial value to true to show loading spinner on first load
loading = true;
constructor(private router: Router) {
router.events.subscribe((event: RouterEvent) => {
this.navigationInterceptor(event);
});
}
// Shows and hides the loading …Run Code Online (Sandbox Code Playgroud)