Street view map : Map « Core Class « Android






Street view map

   

package app.test;

import android.os.Bundle;
import android.view.View;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

class ClickReceiver extends Overlay{
  private static final String TAG = "ClickReceiver";
  private Context mContext;

  public ClickReceiver(Context context) {
        mContext = context;
  }
  
  @Override
  public boolean onTap(GeoPoint p, MapView mapView) {
    Log.v(TAG, "Received a click at this point: " + p);
    if(mapView.isStreetView()) {
            Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse
            ("google.streetview:cbll=" +
            (float)p.getLatitudeE6() / 1000000f +
            "," + (float)p.getLongitudeE6() / 1000000f
              +"&cbp=1,180,,0,1.0"
                ));
        mContext.startActivity(myIntent);
        return true;
    }
      return false;
  }
}

public class MainActivity extends MapActivity
{
    private MapView mapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView = (MapView)findViewById(R.id.mapview);
        ClickReceiver clickRecvr = new ClickReceiver(this);
        mapView.getOverlays().add(clickRecvr);
        mapView.invalidate();
    }

    public void myClickHandler(View target) {
        switch(target.getId()) {
        case R.id.zoomin:
          mapView.getController().zoomIn();
          break;
        case R.id.zoomout:
          mapView.getController().zoomOut();
          break;
        case R.id.sat:
          mapView.setSatellite(true);
          break;
        case R.id.street:
          mapView.setStreetView(true);
          break;
        case R.id.traffic:
          mapView.setTraffic(true);
          break;
        case R.id.normal:
          mapView.setSatellite(false);
          mapView.setStreetView(false);
          mapView.setTraffic(false);
          break;
        }
        mapView.postInvalidateDelayed(2000);
    }
    @Override
    protected boolean isLocationDisplayed() {
        return false;
    }

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

//main.xml

<?xml version="1.0" encoding="utf-8"?>
  <!-- This file is /res/layout/mapview.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <Button android:id="@+id/zoomin" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:text="+"
      android:onClick="myClickHandler" android:padding="12px" />

    <Button android:id="@+id/zoomout" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:text="-"
      android:onClick="myClickHandler" android:padding="12px" />

    <Button android:id="@+id/sat" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:text="Satellite"
      android:onClick="myClickHandler" android:padding="8px" />

    <Button android:id="@+id/street" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:text="Street"
      android:onClick="myClickHandler" android:padding="8px" />

    <Button android:id="@+id/traffic" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:text="Traffic"
      android:onClick="myClickHandler" android:padding="8px" />

    <Button android:id="@+id/normal" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:text="Normal"
      android:onClick="myClickHandler" android:padding="8px" />

  </LinearLayout>

  <com.google.android.maps.MapView
    android:id="@+id/mapview" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:clickable="true"
    android:apiKey="YourKey" />

</LinearLayout>

   
    
    
  








Related examples in the same category

1.Using Google Map
2.Street view map pinch zoom
3.extends ItemizedOverlay
4.My Position Overlay