Bom, estou fazendo uma aplicação que envolve mapas, no entanto, esta dando esse erro.
06-15 00:23:22.841: E/AndroidRuntime(19278): FATAL EXCEPTION: main
06-15 00:23:22.841: E/AndroidRuntime(19278): java.lang.RuntimeException: Unable to resume activity {com.example.mapadeamigos/com.example.mapadeamigos.AmigoMapa}: java.lang.IllegalArgumentException: no position in marker options
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2621)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2649)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.ActivityThread.access$700(ActivityThread.java:134)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.os.Looper.loop(Looper.java:137)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.ActivityThread.main(ActivityThread.java:4867)
06-15 00:23:22.841: E/AndroidRuntime(19278): at java.lang.reflect.Method.invokeNative(Native Method)
06-15 00:23:22.841: E/AndroidRuntime(19278): at java.lang.reflect.Method.invoke(Method.java:511)
06-15 00:23:22.841: E/AndroidRuntime(19278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
06-15 00:23:22.841: E/AndroidRuntime(19278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
06-15 00:23:22.841: E/AndroidRuntime(19278): at dalvik.system.NativeStart.main(Native Method)
06-15 00:23:22.841: E/AndroidRuntime(19278): Caused by: java.lang.IllegalArgumentException: no position in marker options
06-15 00:23:22.841: E/AndroidRuntime(19278): at maps.au.i.a(Unknown Source)
06-15 00:23:22.841: E/AndroidRuntime(19278): at maps.aj.bk.a(Unknown Source)
06-15 00:23:22.841: E/AndroidRuntime(19278): at maps.aj.al.a(Unknown Source)
06-15 00:23:22.841: E/AndroidRuntime(19278): at bcn.onTransact(SourceFile:167)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.os.Binder.transact(Binder.java:326)
06-15 00:23:22.841: E/AndroidRuntime(19278): at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.addMarker(Unknown Source)
06-15 00:23:22.841: E/AndroidRuntime(19278): at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
06-15 00:23:22.841: E/AndroidRuntime(19278): at com.example.mapadeamigos.mapas.MapaFragment.onResume(MapaFragment.java:30)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.support.v4.app.Fragment.performResume(Fragment.java:1503)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1871)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:455)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:444)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.Activity.performResume(Activity.java:5134)
06-15 00:23:22.841: E/AndroidRuntime(19278): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2611)
06-15 00:23:22.841: E/AndroidRuntime(19278): ... 12 more
Essa seria a classe principal que trabalha com o mapa
[code]
package com.example.mapadeamigos;
import java.io.Serializable;
import com.example.mapadeamigos.mapas.AtualizadorDePosicao;
import com.example.mapadeamigos.mapas.Localizador;
import com.example.mapadeamigos.mapas.MapaFragment;
import com.google.android.gms.maps.model.LatLng;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
public class AmigoMapa extends FragmentActivity {
private AtualizadorDePosicao atualizadorDePosicao;
private Amigos escolha;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.mapa_layout);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
MapaFragment mapa=new MapaFragment();
transaction.replace(R.id.mapa_amigos, mapa);
transaction.commit();
Intent intent = getIntent();
escolha = (Amigos) intent.getSerializableExtra("procura");
if(escolha!=null){
Localizador localizador = new Localizador(this);
LatLng local = localizador.getCordenada(escolha.getEndereco());
mapa.carregaMapa(local);
} else {
atualizadorDePosicao = new AtualizadorDePosicao(this,mapa);
}
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if(escolha==null){
atualizadorDePosicao.cancelar();
}
}
}[/code]
classe do gps
[code]
package com.example.mapadeamigos.mapas;
import com.google.android.gms.maps.model.LatLng;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
public class AtualizadorDePosicao implements LocationListener {
private LocationManager locationManager;
private final MapaFragment mapa;
public AtualizadorDePosicao(Activity activity,MapaFragment mapa) {
this.mapa = mapa;
locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
String provider=LocationManager.GPS_PROVIDER;
long minTime=20000;//segundos
float minDistance=20;//metros
locationManager.requestLocationUpdates(provider, minTime, minDistance, this);
}
@Override
public void onLocationChanged(Location novaLocalizacao) {
double latitude = novaLocalizacao.getLatitude();
double longitude = novaLocalizacao.getLongitude();
LatLng local=new LatLng(latitude, longitude);
mapa.carregaMapa(local);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
public void cancelar() {
locationManager.removeUpdates(this);
}
}[/code]
E finalmente MapaFragment
[code]
package com.example.mapadeamigos.mapas;
import java.util.List;
import android.support.v4.app.FragmentActivity;
import com.example.mapadeamigos.Amigos;
import com.example.mapadeamigos.DAO.AmigosDAO;
import com.google.android.gms.maps.CameraUpdate;
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;
public class MapaFragment extends SupportMapFragment {
@Override
public void onResume() {
super.onResume();
FragmentActivity context = getActivity();
//coloca os amigos no mapa
AmigosDAO dao = new AmigosDAO(context);
List<Amigos> amigos = dao.getList();
for(Amigos amigo:amigos){
GoogleMap mapa = getMap();
LatLng localAmigo=new Localizador(context).getCordenada(amigo.getEndereco());
MarkerOptions options=new MarkerOptions().title(amigo.getNome()).position(localAmigo);
mapa.addMarker(options);
}
dao.close();
}
//centraliza mapa
public void carregaMapa(LatLng local) {
GoogleMap map = getMap();
CameraUpdate update=CameraUpdateFactory.newLatLngZoom(local, 15);
map.animateCamera(update);
}
}[/code]
Obrigado