Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 4 Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 4 Application Development
This is the forum to discuss the Wrox book Professional Android 4 Application Development Reto Meier; ISBN: 978-1-1181-0227-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 1st, 2014, 09:37 AM
Authorized User
Points: 89, Level: 1
Points: 89, Level: 1 Points: 89, Level: 1 Points: 89, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
Default Mapping earthquake example using api v2

Chapter 13 in the book handles mapping of all earthquakes found in the database.
It would be more clear to select one quake from the listfragment (sometimes many spots are very close together) and show the map of that one by clicking the map part on the screen.
Moreover it would be nice to build the map using api v2, working with GoogleMap. The EarthquakeOverlay class is then no more necessary.
For that :
1. keep class Earthquake as Activity (no MapActivity)

2. insert in manifest :
Code:
  <permission
      android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
      android:protectionLevel="signature" />

  <uses-feature
      android:glEsVersion="0x00020000"
      android:required="true" />

  <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.VIBRATE"/>
, insert also
Code:
<uses-library android:name="com.google.android.maps"/>
under <application
, insert also
Code:
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="API_KEY" />
under <application
(the API_KEY should be generated from the SHA-1 fingerprint; see https://developers.google.com/maps/d...e_maps_api_key).
SHA-1 fingerprint can easily be read from eclipse menu preferences tab android subtab build.

3. EarthquakeMapFragment :
Code:
package com.paad.earthquake;

import android.app.Fragment;
import android.location.Location;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class EarthquakeMapFragment extends Fragment {
  public static Quake clickedEarthquake=null;
  
  MapView mapview;
  GoogleMap googlemap;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      // inflate and return the layout
      View v = inflater.inflate(R.layout.map_fragment, container, false);
      mapview = (MapView)v.findViewById(R.id.mapview);

      return v;
  }

  @Override
   public void onResume() {
       super.onResume();
       mapview.onResume();
   }
    
   @Override
   public void onPause() {
       mapview.onPause();
       super.onPause();
   }
    
   @Override
   public void onDestroy() {
 	  if (mapview != null)
 		  mapview.onDestroy();
       super.onDestroy();
   }
    
   @Override
   public void onLowMemory() {
       super.onLowMemory();
       mapview.onLowMemory();
   }
 
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
	super.onActivityCreated(savedInstanceState);
	mapview.onCreate(savedInstanceState);
	Earthquake earthquakeActivity = (Earthquake)getActivity();
    try {
	     MapsInitializer.initialize(earthquakeActivity);
	  	  if( clickedEarthquake != null) {
	  		  Location location = clickedEarthquake.getLocation();
		      LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());
		      googlemap = mapview.getMap();

		      if( googlemap != null) {
			      CameraUpdate center= CameraUpdateFactory.newLatLng(latlng);
			      CameraUpdate zoom=CameraUpdateFactory.zoomTo(2);
	
			      googlemap.moveCamera(center);
			      googlemap.animateCamera(zoom);
			      String markerText = clickedEarthquake.getDetails();
			      googlemap.addMarker(new MarkerOptions().position(latlng).title(markerText));
		      } else {
		    	Toast.makeText(earthquakeActivity, "GoogleMap == null!", Toast.LENGTH_LONG).show();  
		      }

		  }
	 } catch (Exception e) {
		 Toast.makeText(earthquakeActivity, "Exceptie : "+e.toString(), Toast.LENGTH_LONG).show();
	 }
    }
  }
Keep in mind that the object clickedEarthquake should be made in EarthquakeListFragment, after having selected a quake from the list.
Also these are just directions to use api v2 for quake map display, not the detailed story!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Facebook api vs Twitter api aspless Classic ASP Basics 4 September 11th, 2017 09:51 AM
Chapter 7 Earthquake 2, Earthquake.java, error onActivityResult dbomberg BOOK: Professional Android 2 Application Development 2 November 30th, 2012 05:52 AM
Difference between lightweight BC api and the other normal API? boy18nj BOOK: Beginning Cryptography with Java 2 June 19th, 2011 09:13 PM
Mapping Earthquake chapters 8-9-10 raychenon BOOK: Professional Android 2 Application Development 1 July 29th, 2010 07:29 PM
IE7 Beta v2 crmpicco HTML Code Clinic 0 February 15th, 2006 05:08 AM



All times are GMT -4. The time now is 01:15 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.