Listing 1013 srccomcookbookmylocationMyLocationjava

package com.cookbook.mylocation;

import java.io.IOException; import java.util.List;

import android.content.Context;

import android.content.Intent;

import android.graphics.Color;

import android.graphics.drawable.Drawable;

import android.location.Address;

import android.location.Geocoder;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

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;

public class MyLocation extends MapActivity { TextView tv;

List<Overlay> mapOverlays; MyMarkerLayer markerlayer; private MapController mc; MapView.LayoutParams mScreenLayoutParams;

public static Context mContext;

^Override public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState); mContext = this; setContentView(R.layout.main);

MapView mapView = (MapView) findViewByld(R.id.mapl); mc = mapView.getController(); tv = (TextView) findViewByld(R.id.tvl); mapOverlays = mapView.getOverlays(); Drawable drawable =

this.getResources().getDrawable(R.drawable.icon); markerlayer = new MyMarkerLayer(drawable);

List<Address> addresses;

String myAddress="1600 Amphitheatre Parkway, Mountain View, CA";

Geocoder gc = new Geocoder(this); try {

addresses = gc.getFromLocationName(myAddress, 1); if(addresses != null) {

Address x = addresses.get(0);

StringBuilder mSB = new StringBuilder("Address:\n"); geolat =(int)(x.getLatitude()*1E6); geolon = (int)(x.getLongitude()*1E6); mSB.append("latitude: ").append(geolat).append("\n"); mSB.append("longitude: ").append(geolon); tv.setText(mSB.toString());

} catch(IOException e) {

tv.setText(e.getMessage());

new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT, x,y,MapView.LayoutParams.LEFT);

final TextView tv = new TextView(this); tv.setText("Adding View to Google Map"); tv.setTextColor(Color.BLUE); tv.setTextSize(20);

mapView.addView(tv, mScreenLayoutParams);

mScreenLayoutParams =

new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT, x,y,

MapView.LayoutParams.BOTTOM_CENTER);

Button clickMe = new Button(this); clickMe.setText("Click Me");

clickMe.setOnClickListener(new OnClickListener() { public void onClick(View v) { tv.setTextColor(Color.RED); tv.setText("Let's play");

mapView.addView(clickMe, mScreenLayoutParams);

@Override protected boolean isRouteDisplayed() { return false; }

Figure 10.6 Adding views to a map.
Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook


Post a comment