2012-02-22 4 views
1

Google지도를 표시 할 수있는 Android 용 위젯을 만들려고합니다. 비록 내가 MapActivity 및 AppWidgetProvider 함께 다른 상속하는 두 클래스를 만들었지 만 그들을 사용하는 방법을 잘 모르겠습니다. 어느 누구라도 그것을 도울 수 있습니까?android에서 위젯으로 Google지도를 만드는 방법

package com.leaning.widget; 

import android.app.PendingIntent; 
import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.widget.RemoteViews; 

public class MapWidgo extends AppWidgetProvider { 

MapGoogle obj = new MapGoogle(); 

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
    int[] appWidgetIds) { 
// TODO Auto-generated method stub 
super.onUpdate(context, appWidgetManager, appWidgetIds); 

for(int i=0;i<appWidgetIds.length;i++) 
{ 
    int appWidgetId = appWidgetIds[i]; 

    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://maps.google.com")); 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 

    RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.main); 
    remote.setOnClickPendingIntent(R.id.webView1, pendingIntent); 

    appWidgetManager.updateAppWidget(appWidgetId, remote); 

} 
} 
}  

이제 아래에있는 내 MapGoogle 클래스

package com.leaning.widget; 

import android.content.Context; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 

public class MapGoogle extends MapActivity { 
@Override 
protected void onCreate(Bundle icicle) { 
    // TODO Auto-generated method stub 
    super.onCreate(icicle); 

    MapView mapview = (MapView) findViewById(R.id.mySecretMap); 
    mapview.setBuiltInZoomControls(true); 

    final MapController controller = mapview.getController(); 

    LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

    LocationListener listener = new LocationListener() { 

     public void onStatusChanged(String provider, int status, Bundle extras) { 
      // TODO Auto-generated method stub 

     } 

     public void onProviderEnabled(String provider) { 
      // TODO Auto-generated method stub 

     } 

     public void onProviderDisabled(String provider) { 
      // TODO Auto-generated method stub 

     } 

     public void onLocationChanged(Location location) { 
      // TODO Auto-generated method stub 
      controller.setCenter(new GeoPoint((int)location.getLongitude(),(int)location.getLatitude())); 
     } 
    }; 

    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, listener); 
} 

@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
} 
} 

이며, 마지막 하나는 내 매니페스트 파일

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.leaning.widget" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="10" /> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

<application 

    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <uses-library android:name="com.google.android.maps" /> 

    <receiver android:name=".MapWidgo"> 

     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

     <meta-data android:name="android.appwidget.provider"  android:resource="@xml/widgetresource"/> 
    </receiver> 

    <activity android:name=".MapGoogle"> 

    </activity> 

</application> 

나는 빠른 해결책을 원하는입니다! 이 Link.it에서

+0

이것으로 어떤 성공을 거두었습니까? 내 홈 화면에 '미니 Google 맵'위젯을 갖고 싶습니다! –

+0

나는 나의 연구를했으나 그때 대답을 얻지 못했고, 나는 그것을 남겼다. 어떤 성공이라도 얻으면 답을 공유하십시오. – iConfused

답변

0

봐는

+0

위젯에서 Google지도를 원합니다. 당신이 제공 한 링크는 Google지도 – iConfused

+2

을 보여줍니다. 나는 그것을 스스로 알아 냈습니다! 위젯에서 map api를 사용할 수 없습니다! 그건 안드로이드의 제한이야! – iConfused

+0

고마워, 나는 똑같은 것을 찾고 있었다. 너무 나빴어. – Stefan

0

http://www.vogella.de/articles/AndroidLocationAPI/article.html 어쩌면 당신이 구글에서지도 URL을 읽고 웹 서비스를 가지고 이미지로 변환 할 수 있습니다 .. 도움이 될 수 있습니다. 당신이 필요로하는 것은 단순히 웹 URL에서 이미지를 표시 할 수있는 위젯입니다 (재생시 많은 것들이 있습니다).

관련 문제