java - Why getOverlays() is undefined for the MapView? -


my qestion might easy sinse i'm android begginer.

i'm following the tutorial

and have succeed in first part of creating map activity. i'm trying add overlay items. problem in .java code:

    list<overlay> mapoverlays = mapview.getoverlays(); 

this line presented in tutorials. error message like: 'the method getoverlays() undefined type mapview'. can me solve it?

code:

    package com.example.mapsdemo;     import java.util.list;     import com.google.android.gms.maps.mapview;     import com.google.android.maps.geopoint;     import com.google.android.maps.overlay;     import com.google.android.maps.overlayitem;     import android.app.activity;     import android.graphics.drawable.drawable;     import android.os.bundle;      public class mainactivity extends activity {  private mapview mapview;      @override     protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      list<overlay> mapoverlays = mapview.getoverlays();     drawable drawable = this.getresources().getdrawable(r.drawable.marker);     helloitemizedoverlay itemizedoverlay = new helloitemizedoverlay(drawable, this);      geopoint point = new geopoint(19240000,-99120000);     overlayitem overlayitem = new overlayitem(point, "hola, mundo!", "i'm in mexico city!");      itemizedoverlay.addoverlay(overlayitem);     mapoverlays.add(itemizedoverlay);      } } 

the second class here:

    public class helloitemizedoverlay extends itemizedoverlay {  private arraylist<overlayitem> moverlays = new arraylist<overlayitem>(); public context mcontext ;  public helloitemizedoverlay(drawable defaultmarker) {       super(boundcenterbottom(defaultmarker));     }  public helloitemizedoverlay(drawable defaultmarker, context context) {       super(boundcenterbottom(defaultmarker));       mcontext = context;     }  public void addoverlay(overlayitem overlay) {     moverlays.add(overlay);     populate(); }  @override protected overlayitem createitem(int i) {   return moverlays.get(i); }  @override public int size() {   return moverlays.size(); }  @override protected boolean ontap(int index) {   overlayitem item = moverlays.get(index);   alertdialog.builder dialog = new alertdialog.builder(mcontext);   dialog.settitle(item.gettitle());   dialog.setmessage(item.getsnippet());   dialog.show();   return true; }  } 

thanks help!

you mixing deprecated api v1 api v2.

i'd suggest removing code , following instead: https://developers.google.com/maps/documentation/android/start


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -