开发者

setting marker to location from string android-google-maps-api

I have a map and I want to be able add in a location from a string and have it add a marker on that location. so far I have some code that that I thought might work but i keep getting errors. I will post the code.

First Activity

LON = (E开发者_JAVA技巧ditText) findViewById (R.id.LON);
LAT = (EditText) findViewById (R.id.LAT);
SL  = (Button)   findViewById (R.id.SL);

SL.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            Intent intent = new Intent (SetLocation.this,GarageSellerActivity.class);
            intent.putExtra("lonstring", LON.getText().toString());
            intent.putExtra("latstring", LAT.getText().toString());
            startActivity(intent);
        }
});

The first activity has no errors and works as far as going to the next activity.

Second Activity

private String          LONString;
private String          LATString;

//**Turns longitude EditText into a string**\\
LONString = getIntent().getExtras().getString("lonstring", "");
//**Turns latitude EditText into a string.**\\
LATString = getIntent().getExtras().getString("latstring", "");

GeoPoint point1 = new GeoPoint(LONString,+LATString);
OverlayItem overlayitem1 = new OverlayItem(point1, "Sekai, konichiwa!", "I'm in Japan!");

itemizedoverlay1.addOverlay(overlayitem1);
mapOverlays2.add(itemizedoverlay1);'

I have errors on both .getString and on LONString and LATString inside the geopoints. Any help is appreciated.

-Thanks


You need to pass Longitude and Latitude as Integers, not Strings. Just convert them when you pass them to GeoPoint. Like this:

GeoPoint point1 = new GeoPoint(Integer.parseInt(LONString), Integer.parseInt(LATString));

You might want to do some filtering in your input as well to make sure they're not passing anything nasty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜