20.11.2016 Views

ANDROID APP

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

272 บทที่ 10 การระบุตำาแหน่ง<br />

List mapOverlays;<br />

MyMarkerLayer markerlayer;<br />

private MapController mc;<br />

MapView.LayoutParams mScreenLayoutParams;<br />

public static Context mContext;<br />

@Override<br />

public void onCreate(Bundle savedInstanceState) {<br />

super.onCreate(savedInstanceState);<br />

mContext = this;<br />

setContentView(R.layout.main);<br />

MapView mapView = (MapView) findViewById(R.id.map1);<br />

mc = mapView.getController();<br />

tv = (TextView) findViewById(R.id.tv1);<br />

mapOverlays = mapView.getOverlays();<br />

Drawable drawable =<br />

this.getResources().getDrawable(R.drawable.icon);<br />

markerlayer = new MyMarkerLayer(drawable);<br />

List addresses;<br />

String myAddress="1600 Amphitheatre Parkway, Mountain View, CA";<br />

int geolat = 0;<br />

int geolon = 0;<br />

Geocoder gc = new Geocoder(this);<br />

try {<br />

addresses = gc.getFromLocationName(myAddress, 1);<br />

if(addresses != null) {<br />

Address x = addresses.get(0);<br />

StringBuilder mSB = new StringBuilder("Address:\n");<br />

geolat =(int)(x.getLatitude()*1E6);<br />

geolon = (int)(x.getLongitude()*1E6);<br />

mSB.append("latitude: ").append(geolat).append("\n");<br />

mSB.append("longitude: ").append(geolon);<br />

tv.setText(mSB.toString());<br />

}<br />

} catch(IOException e) {<br />

tv.setText(e.getMessage());<br />

}<br />

int x = 50;<br />

int y = 50;<br />

mScreenLayoutParams =<br />

new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,<br />

MapView.LayoutParams.WRAP_CONTENT,<br />

x,y,MapView.LayoutParams.LEFT);<br />

final TextView tv = new TextView(this);<br />

tv.setText("Adding View to Google Map");<br />

tv.setTextColor(Color.BLUE);<br />

tv.setTextSize(20);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!