>

Fórum

Fórum da RL System, voltado para analistas, programadores etc. Tudo sobre linguagem de programação e desenvolvimento Full Stack: Banco de Dados, Android, C#, Java, .NET, PHP, Node, Javascript, TypeScript, Front, HTML e muito mais.



Mapas v2 - Trava rodando no celular : Vendas Parou


Bom dia, mesmo refazendo a parte do mapa assistindo a aula 10 do mapa v2, quando instalo no celular e clico no listview com as coordenadas ele aparece a mensagem de erro "VENDAS PAROU", passei por diversas vezes pelo Manifest, e MapShowActivity e tambem o ListarVendasActivity e não consegui sanar o problema.

Por favor me dêem uma luz para continuar o projeto.

Segue anexos:
MapaShowActivity:

package br.com.htecno.vendas;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

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;
import br.com.htecno.vendas.R;



public class MapShowActivity extends FragmentActivity{

private GoogleMap map;
private LatLng location;
//private LatLng location = new LatLng(-23.648344, -46.798884);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapa);

Intent it = getIntent();
it.getDoubleExtra("latitude", 0);
it.getDoubleExtra("longitude", 0);

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapa_view)).getMap();

MarkerOptions marcador1 = new MarkerOptions();
marcador1.position(location);
marcador1.title("Testando essa Budega");
map.addMarker(marcador1);

map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 20));

map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);


}


ListarVendasActivity:

//AO CLICAR MOSTRAR O MAPA
ltwVendas.setOnItemClickListener(new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView ad, View v,
int position, long id) {

SQLiteCursor c = (SQLiteCursor)ad.getAdapter().getItem(position);
Intent it = new Intent(getBaseContext(), MapShowActivity.class);
it.putExtra("latitude", c.getDouble(c.getColumnIndex("la")));
it.putExtra("longitude", c.getDouble(c.getColumnIndex("lo")));
startActivity(it);
}
});


VendasManifest:


package="br.com.htecno.vendas"
android:versionCode="1"
android:versionName="1.0" >

android:minSdkVersion="8"
android:targetSdkVersion="17" />

android:name="br.com.htecno.vendas.MAPS_RECEIVE"
android:protectionLevel="signature"/>









android:glEsVersion="0x00020000"
android:required="true"/>

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name="br.com.htecno.vendas.MainActivity"
android:label="@string/app_name" >













android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBtMbpcVEz7F3bpfWEetlVEBvB539XXd3A"/>














10 Respostas


Ola Hercules

e a variavel location ???

ta faltando ai no seu codigo

location = new LatLng(la, lo);




Opa ... Boa Tarde Camarada.. é verdade havia esquecido... agora declarei assim

private double la;
private double lo;
private LatLng location = new LatLng(la, lo);

Daí parou o erro, porém o mapa aparece todo azul... talvez seja pq as coordenadas o celular gravou errado né?




Ola Herculles

vc esta usando o emulador ou o celular??




Opa Boa Noite Camarada!!

Então.. estou usando o celular, Motorola Raz D3... tentei tambem em um emulador o Start Andy, não sei se vc conhece... porem não foi.




mostre como ficou seu codigo agora




Fala André.. .segue abaixo o MapShowActivity, ListarVendasActivity e o Vendas Manifest


////// MapShowActivity

package br.com.htecno.vendas;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

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;
import br.com.htecno.vendas.R;



public class MapShowActivity extends FragmentActivity{

private GoogleMap map;
private double la;
private double lo;
private LatLng location = new LatLng(la, lo);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapa);

Intent it = getIntent();
it.getDoubleExtra("latitude", 0);
it.getDoubleExtra("longitude", 0);

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapa_view)).getMap();

MarkerOptions marcador1 = new MarkerOptions();
marcador1.position(location);
marcador1.title("Testando essa Budega");
map.addMarker(marcador1);

map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 20));

map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);


}



}








Opa... faltou o ListarVendasActivity pra vc comparar


////// ListarVendasActivity
package br.com.htecno.vendas;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class ListarVendasActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listar_vendas);

SQLiteDatabase db = openOrCreateDatabase("vendas.db", Context.MODE_PRIVATE, null);//ABRO O BANCO PARA TRAZER

ListView ltwVendas = (ListView)findViewById(R.id.ltwVendas);


Cursor cursor = db.rawQuery("SELECT vendas._id, vendas.preco, vendas.la, vendas.lo, produtos.nome FROM vendas INNER JOIN produtos on produtos._id = vendas.produto", null);
//crio as colunas que ele vai trazer no spinner em forma de ARRAY
String[] from = { "_id", "preco", "nome", "la", "lo"};
int[] to = {R.id.ltxvID, R.id.ltxvPreco, R.id.ltxvNome, R.id.txvLa, R.id.txvLo};

//PASSO O CURSOR E FAÇO UM NOVO XML PARA O SPINNER
SimpleCursorAdapter ad = new SimpleCursorAdapter(getBaseContext(), R.layout.model_listar, cursor, from, to, 0);
ltwVendas.setAdapter(ad);

//AO CLICAR MOSTRAR O MAPA
ltwVendas.setOnItemClickListener(new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView ad, View v,
int position, long id) {

SQLiteCursor c = (SQLiteCursor)ad.getAdapter().getItem(position);
Intent it = new Intent(getBaseContext(), MapShowActivity.class);
it.putExtra("latitude", c.getDouble(c.getColumnIndex("la")));
it.putExtra("longitude", c.getDouble(c.getColumnIndex("lo")));
startActivity(it);
}
});



}

}









.... E o Vendas Manifest

[XML]


package="br.com.htecno.vendas"
android:versionCode="1"
android:versionName="1.0" >

android:minSdkVersion="8"
android:targetSdkVersion="17" />

android:name="br.com.htecno.vendas.MAPS_RECEIVE"
android:protectionLevel="signature"/>









android:glEsVersion="0x00020000"
android:required="true"/>

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name="br.com.htecno.vendas.MainActivity"
android:label="@string/app_name" >













android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBtMbpcVEz7F3bpfWEetlVEBvB539XXd3A"/>









[/XML]




Opa Herculles,

vc nao deve fazer assim

private LatLng location = new LatLng(la, lo);

faz assim

private GoogleMap map;
private double la;
private double lo;
private LatLng location;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapa);

Intent it = getIntent();
la = it.getDoubleExtra("latitude", 0);
lo = it.getDoubleExtra("longitude", 0);
location = new LatLng(la, lo);

e se vc quiser usar genymotion

va no meu blog

andreleonis.blogspot.com.br

la eu ensino a utilizar o genymotion e vc nem usa seu celular para poder ver no mapa




Opa .... Bom dia meu camarada!!!

Valeu demais por suas dicas vou testá-las hoje.

Abraço.