Errors Fatal Exception on Two activities - android

enter code here
05-31 00:26:46.295: ERROR/AndroidRuntime(4111): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): FATAL EXCEPTION: main
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): java.lang.RuntimeException: Unable to start activity ComponentInfo{yaraby.y/yaraby.y.yarab}: java.lang.NullPointerException
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at a ndroid.app.ActivityThread.access$2300(ActivityThread.java:126)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.os.Looper.loop(Looper.java:123)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.main(ActivityThread.java:4633)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at java.lang.reflect.Method.invoke(Method.java:521)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at dalvik.system.NativeStart.main(Native Method)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): Caused by: java.lang.NullPointerException
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at yaraby.y.yarab.onCreate(yarab.java:92)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): ... 11 more
Yaraby Code
enter code here
public class yaraby extends Activity {
/** Called when the activity is first created. */
String sentence,sentence1, modifiedSentence;;
EditText inputfld, txt;
TextView Text;
Button Enter, Connect, next;
Socket clientSocket;
DataOutputStream outToServer;
BufferedReader inFromServer ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inputfld=(EditText)findViewById(R.id.input);
Text=(TextView)findViewById(R.id.view);
Enter=(Button)findViewById(R.id.enter);
Connect=(Button)findViewById(R.id.connect);
Text.append( "\n about to create a socket");
txt=(EditText)findViewById(R.id.txt);
next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try{
Text.append("PPPPP");
Intent i = new Intent(yaraby.this, yarab.class);
startActivity(i);
Text.append("OPS");
}
catch(Error e){
Log.e("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", e.getMessage());
Text.append("ofa7ay");
}
}});
}
public void appendText(View view){
Text.append( "\n In chat ");
try{
sentence=inputfld.getText().toString();
sentence1="ingyyyy";
Text.append( "\n DataStream creating");
outToServer.writeBytes(sentence);
outToServer.writeBytes(sentence1);
Thread.sleep(1000);
modifiedSentence = inFromServer.readLine();
Text.append(modifiedSentence);
inputfld.setText(null);
}
catch(Exception modifiedsentence){
Text.append("Exception");
}
}
public void connect(View view){
try{
clientSocket= new Socket("192.168.1.6",54611);
Text.append( "\n created a socket");
outToServer = new DataOutputStream(clientSocket.getOutputStream());
Text.append( "\n created a datastream");
inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
Text.append( "\n created a bufferReader");
outToServer = new DataOutputStream(clientSocket.getOutputStream());
}catch(Exception e){
System.out.println("Error");
}
}
yarab code
enter code here
package yaraby.y;
public class yarab extends MapActivity
{
Socket clientSocket;
TextView Text;
private MapView mapView;
private MapController mc;
DataOutputStream outToServer;
BufferedReader inFromServer ;
Button start;
int error = 50;
GeoPoint p, p2;
List<Overlay> mapOverlays;
Drawable drawable, drawable2;
HelloItemizedOverlay itemizedOverlay, itemizedOverlay2;
LocationManager locationManager;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, mlocListener);
mapView = (MapView) findViewById(R.id.mapView);
// enable Street view by default
mapView.setStreetView(true);
// enable to show Satellite view
mapView.setSatellite(true);
// enable to show Traffic on map
// mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mc.setZoom(12);
addOverLays();
start= (Button) findViewById(R.id.start);
}
public void addOverLays() {
String[] coordinates = { "31.216487288475037", "29.932637214660645",
"30.084123015403748", "51.5002", "-0.1262",
"31.337149143218994" };
double lat = 29.98739718380868, lat2 = 29.987810254096985;
double log = 31.442527770886084, log2 = 31.44258677959442;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint((int) (lat2 * 1E6 ), (int) (log2 * 1E6 ));
p3 = new GeoPoint((int) (lat3 * 1e6), (int) (log3 * 1e6));
p4 = new GeoPoint((int) (lat4 * 1e6), (int) (log4 * 1e6));
p5 = new GeoPoint((int) (lat14* 1e6), (int) (log14 * 1e6));
p6 = new GeoPoint((int) (lat8 * 1e6), (int) (log8 * 1e6));
p7 = new GeoPoint((int) (t1* 1e6), (int) (log15 * 1e6));
p8 = new GeoPoint((int) (lat5 * 1e6), (int) (log5 * 1e6));
p9 = new GeoPoint((int) (lat6 * 1e6), (int) (log6 * 1e6));
p10=new GeoPoint( (int) (t4 * 1e6), (int) (log12 * 1e6));
p11=new GeoPoint( (int) (t2* 1e6), (int) (log14 * 1e6));
p12=new GeoPoint( (int) (t3* 1e6), (int) (log5 * 1e6));
p13=new GeoPoint( (int) (t5* 1e6), (int) (log12 * 1e6));
p14=new GeoPoint( (int) (t6* 1e6), (int) (log11 * 1e6));
p15=new GeoPoint( (int) ((t6+t1)/2* 1e6), (int) (log3 * 1e6));
p15=new GeoPoint( (int) (t3* 1e6), (int) (log11 * 1e6));
p16=new GeoPoint( (int) (lat15* 1e6), (int) (log15 * 1e6));
p17=new GeoPoint( (int) (lat13* 1e6), (int) (log13 * 1e6));
p18=new GeoPoint( (int) (lat9* 1e6), (int) (log9 * 1e6));
p19=new GeoPoint( (int) (lat10* 1e6), (int) (log10 * 1e6));
p20=new GeoPoint( (int) (lat11* 1e6), (int) (log11 * 1e6));
p21=new GeoPoint( (int) (lat12* 1e6), (int) (log12 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.wit);
drawable2 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable, this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2, this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
mc.setZoom(17);
}
public void Location(){
LocationManager myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener1 = new MyLocationListener();
LocationManager mlocManager1 = null;
mlocManager1.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, mlocListener1);
// Get the current location in start-up
GeoPoint initGeoPoint = new GeoPoint((int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
.getLatitude()*1000000),(int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()*1000000));
mc.animateTo(initGeoPoint);
mc.setZoom(16);
drawable21 = this.getResources().getDrawable(R.drawable.ggg);
itemizedOverlay21 = new HelloItemizedOverlay(drawable21,this);
OverlayItem over21 = new OverlayItem(initGeoPoint, "offff", "over21");
itemizedOverlay21.addOverlay(over21);
mapOverlays.add(itemizedOverlay21);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
#Override
public void onLocationChanged(Location loc)
{
GeoPoint point = new GeoPoint((int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
String Text = "My current location is: " +
"Latitud =" + loc.getLatitude()+
"Longitud =" +loc.getLongitude() ;
Toast.makeText(getApplicationContext(),
Text,
Toast.LENGTH_SHORT).show();
mc.animateTo(point);
}
private Resources getResources() {
// TODO Auto-generated method stub
return null;
}
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(),
"Gps Disabled",
Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider)
{
Toast.makeText(getApplicationContext(),
"Gps Enabled",
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
protected boolean isRouteDisplayed() {
return false;
}
}/* End of Class MyLocationListener */
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}

You have a NullPointerException on line 92 of yarab.java, in your onCreate() method. Based on the comment by #dmon, my guess is that you are loading the wrong layout and therefore your attempt to retrieve your MapView fails. However, that is just a guess, since you did not tell us what line 92 of yarab.java actually is.

Related

I m trying to use google maps in my Android App. If I click on any position in the map, i want the search editbox to dispay its location

I m trying to use google maps in my Android App. If I click on any position in the map, i want the search editbox to dispay its location but somehow its not getting updated. I can dispaly a toast bt not the text in my Search box.Please tell me what I am doing wrong. Any help will be highly appreciated. Thanks in advance.
Here is my code
public class GooglemapsActivity extends MapActivity
{
EditText txtSearch;
MapView mapView;
MapController mc;
GeoPoint p;
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
//EditText name = (EditText) this.findViewById(R.id.travelNameText);
// name.setText(txtSearch.getText().toString());
}
class MapOverlay extends com.google.android.maps.Overlay
{
#Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.icon);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
#Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
//---when user lifts his finger---
//---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6,
p.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();
i++)
add += addresses.get(0).getAddressLine(i) + "\n";
}
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
else
return false;
}
}
/** Called when the activity is first created. */
#Override
protected boolean isRouteDisplayed()
{
return false;
}
public void changeMap(String area)
{
mapView = (MapView) findViewById(R.id.mapview);
MapController mc=mapView.getController();
GeoPoint myLocation=null;
double lat = 0;
double lng = 0;
try
{
Geocoder g = new Geocoder(this, Locale.getDefault());
java.util.List<android.location.Address> result=g.getFromLocationName(area, 1);
if(result.size()>0){
Toast.makeText(GooglemapsActivity.this, "country: " +
String.valueOf(result.get(0).getCountryName()), Toast.LENGTH_SHORT).show();
lat = result.get(0).getLatitude();
lng = result.get(0).getLongitude();
EditText name = (EditText) this.findViewById(R.id.txtMapSearch);
name.setText("country: " +
String.valueOf(result.get(0).getCountryName()).toString());
}
else{
Toast.makeText(GooglemapsActivity.this, "record not found"
,Toast.LENGTH_SHORT).show();
return;
}
}
catch(IOException io)
{
Toast.makeText(GooglemapsActivity.this, "Connection Error"
, Toast.LENGTH_SHORT).show();
}
myLocation = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
//Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
mc.animateTo(myLocation);
mc.setZoom(10);
mapView.invalidate();
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
Button btnSearch=(Button) findViewById(R.id.btnSearch);
//txtSearch=(EditText)findViewById(R.id.c);
btnSearch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtSearch=(EditText)findViewById(R.id.txtMapSearch);
String area=txtSearch.getText().toString();
GooglemapsActivity.this.changeMap(area);
}
});
mapView = (MapView) findViewById(R.id.mapview);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
String coordinates[] = {"1.352566007", "103.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
mc.animateTo(p);
mc.setZoom(17);
//---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}
}
use:
EditText name = (EditText) GooglemapsActivity.this.findViewById(R.id.txtMapSearch);
instead of
EditText name = (EditText) this.findViewById(R.id.txtMapSearch);
I got a solution to the problem. In the OnTouchEvent where i am creating the toast, i needed to set the text in my edit box at that position. Thanks for trying though.
here is the code:
public class GooglemapsActivity extends MapActivity
{
EditText txtSearch;
EditText TravelFrom;
MapView mapView;
MapController mc;
GeoPoint p;
class MapOverlay extends com.google.android.maps.Overlay
{
#Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.icon);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
#Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
//---when user lifts his finger---
//---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6,
p.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0)
{
for (int i=0; <addresses.get(0).getMaxAddressLineIndex();
i++)
add += addresses.get(0).getAddressLine(i) + "\n";
}
txtSearch = (EditText) GooglemapsActivity.this.
findViewById(R.id.txtMapSearch);
txtSearch.setText(add);
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
else
return false;
}
}
/** Called when the activity is first created. */
#Override
protected boolean isRouteDisplayed()
{
return false;
}
public void changeMap(String area)
{
mapView = (MapView) findViewById(R.id.mapview);
MapController mc=mapView.getController();
GeoPoint myLocation=null;
double lat = 0;
double lng = 0;
try
{
Geocoder g = new Geocoder(this, Locale.getDefault());
java.util.List<android.location.Address> result=g.getFromLocationName(area, 1);
if(result.size()>0){
Toast.makeText(GooglemapsActivity.this, "country: " + String.
valueOf(result.get(0).getCountryName()), Toast.LENGTH_SHORT).show();
lat = result.get(0).getLatitude();
lng = result.get(0).getLongitude();
//EditText name = (EditText) this.findViewById(R.id.txtMapSearch);
txtSearch = (EditText)GooglemapsActivity.this.findViewById(R.id.txtMapSearch);
txtSearch.setText("country: " + String.valueOf(result.get(0).
getCountryName()).toString());
}
else{
Toast.makeText(GooglemapsActivity.this,"record not
found", Toast.LENGTH_SHORT).show();
return;
}
}
catch(IOException io){
Toast.makeText(GooglemapsActivity.this,"ConnectionError",
Toast.LENGTH_SHORT).show();
}
myLocation = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
// Drawable drawable = this.getResources().getDrawable(R.drawable.bubble);
mc.animateTo(myLocation);
mc.setZoom(10);
mapView.invalidate();
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
Button btnSearch=(Button) findViewById(R.id.btnSearch);
//txtSearch=(EditText)findViewById(R.id.c);
btnSearch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtSearch=(EditText)findViewById(R.id.txtMapSearch);
String area=txtSearch.getText().toString();
GooglemapsActivity.this.changeMap(area);
}
});
Button btnDone=(Button) findViewById(R.id.btnDone);
//txtSearch=(EditText)findViewById(R.id.c);
btnDone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtSearch=(EditText)findViewById(R.id.txtMapSearch);
String area=txtSearch.getText().toString();
//GooglemapsActivity.this.changeMap(area);
TravelFrom=(EditText)findViewById(R.id.travelFromEntry);
TravelFrom.setText(area);
}
});
mapView = (MapView) findViewById(R.id.mapview);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
String coordinates[] = {"1.352566007", "103.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
mc.animateTo(p);
mc.setZoom(17);
//---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}
}

command for removing a specific over lay item

what is The command for removing specific overlay item ?
if here is my code of the added items
public void addOverLays(){
String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 30.084262490272522, lat2 = 51.5002,lat3=29.987091422080994;
double log = 31.33625864982605, log2 = -0.1262,log3=31.43909454345703;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3=new GeoPoint( (int) (lat3 * 1e6), (int) (log3 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.ballon);
drawable2 = this.getResources().getDrawable(R.drawable.ballon);
drawable3 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);
itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay3.addOverlay(over3);
mapOverlays.add(itemizedOverlay3);
Replace add() with remove():
mapView.getOverlays().remove(<putYourOverlayHere>);
mapView.invalidate();

how to make a loop over myoverlay items

how can i make a loop for my overlay items android !! and what if i want to remove one of them by using mapView.getOverlays().remove(p); !! its doesn't work why ?? here is the code
enter code here
public void addOverLays(){
String [] coordinates = {"31.216487288475037","29.932637214660645" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 30.084686279296875,lat2 = 51.5002,lat3=29.987091422080994;
double log = 31.33642494678493, log2 = -0.1262,log3=31.43909454345703;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3=new GeoPoint( (int) (lat3 * 1e6), (int) (log3 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.pushpin);
drawable2 = this.getResources().getDrawable(R.drawable.ballon);
drawable3 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);
itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay3.addOverlay(over3);
mapOverlays.add(itemizedOverlay3);
mc.setZoom(17);
mc.animateTo(p);
}
Adding overlays does work in your code - if you mean you don't see any changes, then you have to call MapView.invalidate() to have it re-draw itself with the newly added overlays. The same is true when you remove an overlay.

Ie6*lat isnt it the same as 1000000*lat? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
package ntryn.n;
import java.util.List;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class ntryn extends MapActivity
{
private MapView mapView;
private MapController mc;
GeoPoint p, p2, p3, p4;
List<Overlay> mapOverlays;
Drawable drawable, drawable2 , drawable3, drawable4;
HelloItemizedOverlay itemizedOverlay, itemizedOverlay2 , itemizedOverlay3, itemizedOverlay4;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
mapView = (MapView) findViewById(R.id.mapView);
// enable Street view by default
mapView.setStreetView(true);
// enable to show Satellite view
// mapView.setSatellite(true);
// enable to show Traffic on map
// mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mapView.setStreetView(true);
//mapView.setSatellite(true);
mc.setZoom(12);
addOverLays();
}
catch(Exception e){
Log.d("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",e.getMessage());
}
}
public void addOverLays(){
String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 30.084262490272522, lat2 = 51.5002,lat3=30.084123015403748;
double log = 31.33625864982605, log2 = -0.1262,log3=31.337149143218994;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3=new GeoPoint( (int) (lat3 * 1000000), (int) (log3 * 1000000));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.ballon);
drawable2 = this.getResources().getDrawable(R.drawable.dotred);
drawable3 = this.getResources().getDrawable(R.drawable.icon);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);
itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay2.addOverlay(over3);
mapOverlays.add(itemizedOverlay3);
mc.setZoom(17);
//mc.animateTo(p);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
#Override
public void onLocationChanged(Location loc)
{
GeoPoint point = new GeoPoint( (int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
//DoubletoString(loc.getLatitude());
//DoubletoString(loc.getLongitude());
String Text = "My current location is: " +
"Latitud ="+ loc.getLatitude() +
"Longitud =" + loc.getLongitude();
Toast.makeText( getApplicationContext(),
Text,
Toast.LENGTH_SHORT).show();
mc.animateTo(point);
}
private void DoubletoString(double latitude) {
// TODO Auto-generated method stub
}
public void onProviderDisabled(String provider)
{
Toast.makeText( getApplicationContext(),
"Gps Disabled",
Toast.LENGTH_SHORT ).show();
}
public void onProviderEnabled(String provider)
{
Toast.makeText( getApplicationContext(),
"Gps Enabled",
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
protected boolean isRouteDisplayed() {
return false;
}
}/* End of Class MyLocationListener */
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
/* End of UseGps Activity*/
it force close. this due to the 3 overlaying items when i add only 2 in other words remove the p3 which is * 1000000. it's work, but with it it doesn't zoom and when i want to zoom it show force close
1e6 is a floating point number, 1000000 is an integer.
[adrian#cheops3:~]> cat Test.java
class Test {
public static void main(String[] args) {
System.out.println("1e6 = " + 1e6);
System.out.println("1000000 = " + 1000000);
}
}
[adrian#cheops3:~]> javac Test.java && java Test
1e6 = 1000000.0
1000000 = 1000000

Android GEOPOINT error

public void addOverLays(){
String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 30.084262490272522, lat2 = 51.5002,lat3=30.084123015403748;
double log = 31.33625864982605, log2 = -0.1262,log3=31.337149143218994;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3 = new GeoPoint( (int) (lat3 * 1E6), (int) (log3 * 1E6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.icon);
drawable2 = this.getResources().getDrawable(R.drawable.pushpin);
drawable3 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);
itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay2.addOverlay(over3);
mapOverlays.add(itemizedOverlay3);
Why can't I add 3 items due to
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3 = new GeoPoint( (int) (lat3 * 1E6), (int) (log3 * 1E6));
can't make 1E6 & 1e6 what other I have to do?!!
you might have a casting issue, hard to tell. Try using this utility method:
public static GeoPoint calculateGeoPoint(double latitude, double longitude) {
Double latE6 = latitude * 1E6;
Double lngE6 = longitude * 1E6;
return new GeoPoint(latE6.intValue(), lngE6.intValue());
}
It's worked reliably for me in tested production code.

Categories

Resources