2013-02-08 2 views
0

자습서 Android Working with Google Places and Maps에서이 코드를 얻었습니다. Google지도 버전 2에서 작동해야하기 때문에이 코드를 변경하고 싶습니다. 문제는지도 대신에 Google 장소 뒤에 그리드 만 표시된다는 것입니다.내 앱 (눈금 만)에 Google 지역 정보 뒤에 표시 할 Google지도를 가져올 수 없습니다.

PlacesMapActivity.java

package com.androidhive.googleplacesandmaps; 

import java.util.List; 

import android.content.Intent; 
import android.graphics.drawable.Drawable; 
import android.os.Bundle; 
import android.util.Log; 

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; 
import com.google.android.maps.OverlayItem; 

public class PlacesMapActivity extends MapActivity { 
    // Nearest places 
    PlacesList nearPlaces; 

    // Map view 
    MapView mapView; 

    // Map overlay items 
    List<Overlay> mapOverlays; 

    AddItemizedOverlay itemizedOverlay; 

    GeoPoint geoPoint; 
    // Map controllers 
    MapController mc; 

    double latitude; 
    double longitude; 
    OverlayItem overlayitem; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map_places); 

     // Getting intent data 
     Intent i = getIntent(); 

     // Users current geo location 
     String user_latitude = i.getStringExtra("user_latitude"); 
     String user_longitude = i.getStringExtra("user_longitude"); 

     // Nearplaces list 
     nearPlaces = (PlacesList) i.getSerializableExtra("near_places"); 

     mapView = (MapView) findViewById(R.id.mapView); 
     mapView.setBuiltInZoomControls(true); 

     mapOverlays = mapView.getOverlays(); 

     // Geopoint to place on map 
     geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6), 
       (int) (Double.parseDouble(user_longitude) * 1E6)); 

     // Drawable marker icon 
     Drawable drawable_user = this.getResources() 
       .getDrawable(R.drawable.mark_red); 

     itemizedOverlay = new AddItemizedOverlay(drawable_user, this); 

     // Map overlay item 
     overlayitem = new OverlayItem(geoPoint, "Your Location", 
       "That is you!"); 

     itemizedOverlay.addOverlay(overlayitem); 

     mapOverlays.add(itemizedOverlay); 
     itemizedOverlay.populateNow(); 

     // Drawable marker icon 
     Drawable drawable = this.getResources() 
       .getDrawable(R.drawable.mark_blue); 

     itemizedOverlay = new AddItemizedOverlay(drawable, this); 

     mc = mapView.getController(); 

     // These values are used to get map boundary area 
     // The area where you can see all the markers on screen 
     int minLat = Integer.MAX_VALUE; 
     int minLong = Integer.MAX_VALUE; 
     int maxLat = Integer.MIN_VALUE; 
     int maxLong = Integer.MIN_VALUE; 

     // check for null in case it is null 
     if (nearPlaces.results != null) { 
      // loop through all the places 
      for (Place place : nearPlaces.results) { 
       latitude = place.geometry.location.lat; // latitude 
       longitude = place.geometry.location.lng; // longitude 

       // Geopoint to place on map 
       geoPoint = new GeoPoint((int) (latitude * 1E6), 
         (int) (longitude * 1E6)); 

       // Map overlay item 
       overlayitem = new OverlayItem(geoPoint, place.name, 
         place.vicinity); 

       itemizedOverlay.addOverlay(overlayitem); 


       // calculating map boundary area 
       minLat = (int) Math.min(geoPoint.getLatitudeE6(), minLat); 
       minLong = (int) Math.min(geoPoint.getLongitudeE6(), minLong); 
       maxLat = (int) Math.max(geoPoint.getLatitudeE6(), maxLat); 
       maxLong = (int) Math.max(geoPoint.getLongitudeE6(), maxLong); 
      } 
      mapOverlays.add(itemizedOverlay); 

      // showing all overlay items 
      itemizedOverlay.populateNow(); 
     } 

     // Adjusting the zoom level so that you can see all the markers on map 
     mapView.getController().zoomToSpan(Math.abs(minLat - maxLat), Math.abs(minLong - maxLong)); 

     // Showing the center of the map 
     mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2)); 
     mapView.postInvalidate(); 

    } 

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

} 

GooglePlaces.java 내가 구글지도에 표시 얻을 관리에도 불구하고, 많은 것을 시도하고 있지만,이 동작하지 않습니다 '

package com.androidhive.googleplacesandmaps; 

import org.apache.http.client.HttpResponseException; 

import android.content.Context; 
import android.util.Log; 

import com.google.api.client.googleapis.GoogleHeaders; 
import com.google.api.client.http.GenericUrl; 
import com.google.api.client.http.HttpRequest; 
import com.google.api.client.http.HttpRequestFactory; 
import com.google.api.client.http.HttpRequestInitializer; 
import com.google.api.client.http.HttpTransport; 
import com.google.api.client.http.javanet.NetHttpTransport; 
import com.google.api.client.http.json.JsonHttpParser; 
import com.google.api.client.json.jackson.JacksonFactory; 

@SuppressWarnings("deprecation") 
public class GooglePlaces { 

    /** Global instance of the HTTP transport. */ 
    private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); 

    // Google API Key 
    private static final String API_KEY = "****my key is here*****"; // my API key Key for browser apps 

    // Google Places search url's 
    private static final String PLACES_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/search/json?"; 
    private static final String PLACES_TEXT_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/search/json?"; 
    private static final String PLACES_DETAILS_URL = "https://maps.googleapis.com/maps/api/place/details/json?"; 

    private double _latitude; 
    private double _longitude; 
    private double _radius; 

    /** 
    * Searching places 
    * @param latitude - latitude of place 
    * @params longitude - longitude of place 
    * @param radius - radius of searchable area 
    * @param types - type of place to search 
    * @return list of places 
    * */ 
    public PlacesList search(double latitude, double longitude, double radius, String types) 
      throws Exception { 

     this._latitude = latitude; 
     this._longitude = longitude; 
     this._radius = 3000; 

     try { 

      HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT); 
      HttpRequest request = httpRequestFactory 
        .buildGetRequest(new GenericUrl(PLACES_SEARCH_URL)); 
      request.getUrl().put("key", API_KEY); 
      request.getUrl().put("location", _latitude + "," + _longitude); 
      request.getUrl().put("radius", _radius); // in meters 
      request.getUrl().put("sensor", "false"); 
      if(types != null) 
       request.getUrl().put("types", types); 

      PlacesList list = request.execute().parseAs(PlacesList.class); 
      // Check log cat for places response status 
      Log.d("Places Status", "" + list.status); 
      return list; 

     } catch (HttpResponseException e) { 
      Log.e("Error:", e.getMessage()); 
      return null; 
     } 

    } 

    /** 
    * Searching single place full details 
    * @param refrence - reference id of place 
    *     - which you will get in search api request 
    * */ 
    public PlaceDetails getPlaceDetails(String reference) throws Exception { 
     try { 

      HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT); 
      HttpRequest request = httpRequestFactory 
        .buildGetRequest(new GenericUrl(PLACES_DETAILS_URL)); 
      request.getUrl().put("key", API_KEY); 
      request.getUrl().put("reference", reference); 
      request.getUrl().put("sensor", "false"); 

      PlaceDetails place = request.execute().parseAs(PlaceDetails.class); 

      return place; 

     } catch (HttpResponseException e) { 
      Log.e("Error in Perform Details", e.getMessage()); 
      throw e; 
     } 
    } 

    /** 
    * Creating http request Factory 
    * */ 
    public static HttpRequestFactory createRequestFactory(
      final HttpTransport transport) { 
     return transport.createRequestFactory(new HttpRequestInitializer() { 
      public void initialize(HttpRequest request) { 
       GoogleHeaders headers = new GoogleHeaders(); 
       headers.setApplicationName("AndroidHive-Places-Test"); 
       request.setHeaders(headers); 
       JsonHttpParser parser = new JsonHttpParser(new JacksonFactory()); 
       request.addParser(parser); 
      } 
     }); 
    } 

} 

내 다른 프로젝트의 장치. 정확히 무엇을 바꾸어야합니까?

내 로그 캣

02-10 16:42:42.479: W/KeyCharacterMap(11974): Can't open keycharmap file 
02-10 16:42:42.479: W/KeyCharacterMap(11974): Error loading keycharmap file '/system/usr/keychars/ft5x02-touchscreen.kcm.bin'. hw.keyboards.65538.devname='ft5x02-touchscreen' 
02-10 16:42:42.479: W/KeyCharacterMap(11974): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 
02-10 16:42:54.067: D/Network(11974): Network Enabled 
02-10 16:42:54.077: D/Your Location(11974): latitude:37.970373475, longitude: 23.772967 
02-10 16:42:54.507: D/Places Status(11974): OK 
02-10 16:42:57.917: D/Place(11974): Agora Ilission S.A.Chatzigianni Mexi 8, Athens, Greece21 0725 225237.97706123.751386 
02-10 16:43:00.407: D/Place(11974): Piu VerdeΣτρατ. Αλ. Παπάγου, Athens, Greece21 0654 618537.99337223.794133 
02-10 16:43:01.127: W/KeyCharacterMap(11974): Can't open keycharmap file 
02-10 16:43:01.127: W/KeyCharacterMap(11974): Error loading keycharmap file '/system/usr/keychars/ft5x02-touchscreen.kcm.bin'. hw.keyboards.65538.devname='ft5x02-touchscreen' 
02-10 16:43:01.127: W/KeyCharacterMap(11974): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 
02-10 16:43:02.497: W/MapActivity(11974): Recycling dispatcher [email protected] 
02-10 16:43:02.507: V/MapActivity(11974): Recycling map object. 
02-10 16:43:02.617: I/MapActivity(11974): Handling network change notification:CONNECTED 
02-10 16:43:02.617: E/MapActivity(11974): Couldn't get connection factory client 

답변

0

체크인 매니페스트

이 허가되고 라이브러리 manifest 태그와

<uses-library android:name="com.google.android.maps" />application 태그에

<uses-permission android:name="android.permission.INTERNET"/>에 따라 같은 추가 사용

그리고 이중 체크는 인터넷에 연결할 수있는 장치입니다.