Tecnologie

Dettaglio dell'articolo:

domenica 08 novembre 2009

GPS e Mappe di Google in Android

Creazione del progetto

Utilizzando Eclipse, creare un nuovo progetto Android e chiamarlo MAPGPS.java.

Per porter utilizzare le funzionalità GPS nella tua appllicazione per Android, devi aggiungere le permission ACCESS_FINE_LOCATION nel file AndroidManifest.xml, per la navigazione con le mappe di google devi aggiungere le permission android.permission.INTERNET e  la direttiva uses-library per l'utilizzo delle librerie per google maps:

=======================================================

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.tests"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <uses-library android:name="com.google.android.maps" />  
    
        <activity android:name=".MAPGPS"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

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

</manifest>

=======================================================

Per porter visualizzare le mappe di google all'interno della propria applcazione, in main.xml, sostituire l'elemento TextView  con l'elemento  MapView:

=======================================================

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
    android:id="@+id/mapview1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="INSERT_KEY_HERE" />
</LinearLayout>


=======================================================

Per poter utilizzare le api di Google Maps, è necessaria una chiave, che va inserita al posto della stringa evidenziata in grassetto.

Generazione della chiave per google maps api

Per la richiesta di Maps API Key, è necessario fornire un'impronta digitale MD5 del certificato che verrà utilizzato per firmare l'applicazione. Prima di visitare la pagina di registrazione (http://code.google. com/android/maps-api-signup.html), utilizzare keytool per generare l'impronta digitale del certificato appropriato.

$ keytool -list -alias androiddebugkey \
-keystore .keystore \
-storepass android -keypass android

Per default, il debug keystore si trova nella directory di lavoro dell'eclipse sdk. Essa varia in ogni piattaforma:

  • Windows Vista: C:\Users\\.android\debug.keystore

  • Windows XP: C:\Documents and Settings\\.android\debug.keystore

  • OS X and Linux: ~/.android/debug.keystore

Creazione del programma java

Riportiamo il listato del programma  MAPGPS.java, per mezzo del quale, quando cambia la posizione geografica per mezzo di una variazione segnalata dal dispositivo GPS, la latitudine e la longitudine viene inviata alle Mappe di Google, che quindi visualizzano la mappa della posizione corrente.

 

=======================================================

package com.android.tests;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

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 MAPGPS extends MapActivity {
    
    private LocationManager lm;
    private LocationListener locationListener;

    private MapView mapView;
    private MapController mc;

    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //---use the LocationManager class to obtain GPS locations---
        lm = (LocationManager)
            getSystemService(Context.LOCATION_SERVICE);    
        
        locationListener = new MyLocationListener();
        
        lm.requestLocationUpdates(
            LocationManager.GPS_PROVIDER,
            2000, 10,
            locationListener);
        
        mapView = (MapView) findViewById(R.id.mapview1);
        mc = mapView.getController();

    }
    
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }    
    
    private class MyLocationListener implements LocationListener
    {
        @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {
                Toast.makeText(getBaseContext(),
                    "Location changed : Lat: " + loc.getLatitude() +
                    " Lng: " + loc.getLongitude(),
                    Toast.LENGTH_SHORT).show();
                
                GeoPoint p = new GeoPoint(
                        (int) (loc.getLatitude() * 1E6),
                        (int) (loc.getLongitude() * 1E6));

                mc.animateTo(p);
                mc.setZoom(16);                
                mapView.invalidate();

            }
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status,
            Bundle extras) {
        }
    }
}

=======================================================

Simulazione del GPS per mezzo dell'emulatore Android


Per porter simulare eventi GPS utilizzando l'emulatore Android, è sufficiente fare telnet all'emulatore ed usare il comando geo per inviare le coordinate GPS:


C:\>telnet localhost 5554
Android Console: type 'help' for a list of commands
OK
geo fix 9.191190 45.464004
OK

Di seguito riportiamo l'immagine della mappa che si deve ottenere all'interno dell'applicazione.

Android Vertual Device

 


Commenti:

Shop Ranked Accounts provide affordable price and instant delivery on cheap csgo smurf ranked accounts.
CSGO prime accounts

Inviato da: preyasi il: 2018-09-14 13:53:54.60491

Today the weather is quite beautiful. I like this. It makes me comfortable and works better. But I tried my best and try to finish the contest with a fierce determination to live up to the expectations of people. outlook entrar

Inviato da: sadas il: 2018-05-07 09:10:45.882918

This is a fantastic website , thanks for sharing. Remedies for Asthma

Inviato da: Remedies for Asthma il: 2018-04-02 20:36:29.468108

Ciao, ho provato a far girare questo esempio ma non funziona e girando altrove (su Google) ho visto che fa "mapView = new MapView(this, "chiave_google_maps"); l'applicazione parte ma non carica le mappe Grazie per eventuali risposte

Inviato da: mikelmanto il: 2011-04-21 17:05:19.847607 According to some rumors about  KonoSuba , the anime will lead Kazuma to get famous amongst the ladies and due to this Aqua will grow jealous. 

Inviato da: gigi il: 2018-06-26 14:12:46.155849 Thank you so much for sharing with us such an interesting post. keep doing a great work. $1 web Hosting

Inviato da: MARIYA il: 2018-09-01 13:26:39.332159 Summer is easy with heavy rain but I like it. It's wonderful to have rainbows after rain, and I watch it until it disappears. It seems to be free but it helps me feel comfortable papas games

Inviato da: sdsdv il: 2018-05-04 10:23:20.22026 It is extremely nice to see the greatest details presented in an easy and understanding manner.

Inviato da: National Caesar Salad Day il: 2018-07-21 14:11:33.436885 I as of late discovered numerous helpful data in your site particularly this site page. Among the loads of remarks on your articles. A debt of gratitude is in order for sharing.

Inviato da: reviews about all term paper writing services il: 2018-06-30 16:23:26.347482 Your share is great geometry dash

Inviato da: geometry dash il: 2018-05-10 10:52:02.538707 This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog review of SigmaEssays.com by bestwritersonline.com. This is a nice blog..

Inviato da: robertfcrocker il: 2018-08-07 23:09:58.372284 I am a new user of this site so here i saw multiple articles and posts posted by this site,I curious more interest in some of them hope you will give more information on this topics in your next articles. Boric Acid Uses

Inviato da: Boric Acid Uses il: 2018-04-02 23:07:14.537727 Thank you so much for ding the impressive job here, everyone will surely like your post. Guava

Inviato da: Guava il: 2018-04-03 19:29:14.626089 1. DPS are committed to provide our students with a sound knowledge base with emphasis on building strong fundamentals in the principles of education, moral values and strong character and concrete the same by the way of continuous training with psychological methods.
Best School in rajasthan
Best CBSE Boarding School in NCR
Admission in CBSE School Rajasthan
Top 10 CBSE school in Rajasthan

Inviato da: sere il: 2018-02-13 12:42:22.995844 Thanks for sharing the wonderful article! This is really informative. I found some interesting things things to do post

Inviato da: things to do il: 2018-06-25 06:00:32.413339 Wishing you the best of luck for all your blogging efforts.This is my first opportunity to chat this website. I found some interesting things and I will apply to the development of my blog. BCA college Punjab

Inviato da: dodra il: 2018-01-09 11:26:03.817767 Just an interesting article that deserves to be shared with other peoples. I have done it. I have biikmaked it for later references. Βερίκοκα

Inviato da: John il: 2018-05-21 21:19:20.748901 Thank you so much for sharing with us such an interesting post.

Inviato da: mariya il: 2018-09-01 13:23:04.876811 Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative. Avriq Avriq India

Inviato da: Robinmax il: 2018-03-27 09:05:03.037479 dDescargar you tv player pro

Inviato da: lover il: 2018-08-12 16:31:27.506257 I returned to photoshop alternative, cool math games run 3

Inviato da: Anna Shetty il: 2017-12-20 03:32:53.253062 I think this is an informative post and it is very useful and knowledgeable. I really enjoyed reading this post. big fan, thank you!

Inviato da: happy wheels il: 2018-06-11 05:36:04.976808 Want to add on to your best custom writing http://customseekdeal.com/about-us/ review? I will be pleased to give you guys a positive review as I really liked your services. If interested, ping me.

Inviato da: robertfcrocker il: 2018-09-16 10:16:45.80072 Inviato da: Jelly il: 2017-11-15 10:34:45.378276 Wishing you the good luck for all your blogging efforts.This is my first chance to visit this site. ac maintenance

Inviato da: edwar139 il: 2018-02-27 11:56:48.684835 It is a good and amazing article. Your information is very useful for me and for others. thank you so much.

Inviato da: Create Hotmail Account il: 2018-06-09 20:24:18.739758 I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon… Remedies For Insomnia

Inviato da: Remedies For Insomnia il: 2018-04-02 18:11:00.149668 Bed Bath and Beyond platform have specially customized gift cards called as Bed Bath and Beyond Gift Cards. Choose from the diverse categories of Bed Bath and Beyond Gift Card Balance to increase the allure of your bonding

Inviato da: liok il: 2018-06-26 14:16:49.449692 The material and aggregation is excellent and telltale as comfortably. dissertation writing services sg private detectives

Inviato da: sg private detectives il: 2018-04-12 23:18:13.126932 Have a natural attraction for women cosmetics and cheap vape uk clothes, no more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment cheap vape uk. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the cheap e-cigarettes.

Inviato da: cheap vape uk il: 2018-05-15 08:44:57.359733 activate vodafone caller tune activate jio caller tune activate airtel caller tune activate idea caller tune idea net balance check airtel net balance check vodafone net balance check jio net balance check bsnl net balance check code idea net balance check code vodafone net balance check code airtel net balance check code docomo net balance check code best laptop under 10000 laptop under 15000 laptop under 20000 laptop under 25000 laptop under 30000 laptop under 35000 laptop under 40000bestpromarket Genxguys best graphics card for gaming under 100 graphics card under 50 photographer in gurgaon

Inviato da: techmaniya il: 2018-05-02 10:49:22.916156 I thank you for the information! I was looking for and could not find. You helped me! boost mobile for live person

Inviato da: boost mobile for live person il: 2018-08-09 10:25:30.846627 I like this post that amazing and interesting. Thanks for share! Visit my home: quotes about time passinge

Inviato da: quotes about time passing il: 2018-09-27 05:40:09.182615 Thanks for your sharing! The information your share is very useful to me and many people are looking for them just like me! Soundcloud Downloader and Soundcloud to MP3 Converter.

Inviato da: Matthew il: 2017-10-27 07:02:21.982512 Thank you have been shared a new Android project, creating the map for the map. it help useful many for me.

Inviato da: run 3 il: 2018-08-31 03:46:08.601748 Thank you so much for sharing with us such an interesting post. keep doing a great work.

Inviato da: Jennifer il: 2018-09-01 13:14:52.077849 The secret of our plain custom quality wholesale boxes is the latest technology that we use. Whether it’s plain Printing or blank Designing, we are equipped with the latest and most advanced technology available in the Industry. If you want plain blank custom cigarette boxes wholesale we are the best in market. We supply different blank plain wholesale boxes in USA. If you’re a new brand in the market, you’ll need an extraordinary design that we can provide to urge people’s attraction.

Inviato da: Custom Product Boxes il: 2018-08-21 14:08:11.446708 http://descargarandroidapks.com/es/descargar-you-tv-player-gratis/

Inviato da: fdsd il: 2018-08-12 16:32:48.462086 Its really good information, i like your blog post. Thanks for sharing 1024x768 Wallpapers

Inviato da: alice F taylor il: 2018-06-18 08:50:59.825678 This Is Really Great Work. Thank You For Sharing Such A Useful Information Here In The Blog.

Inviato da: phenq reviews il: 2018-10-07 20:12:45.837539 I think about it is most required for making more on this get engaged Remedies For Snoring

Inviato da: Remedies For Snoring il: 2018-04-02 16:38:20.94669 Its really good information, i like your blog post. Thanks for sharing gmail account login

Inviato da: gmail account login il: 2018-06-26 12:37:23.948304 Thanks for sharing the wonderful article! This is really informative, happy wheels free.

Inviato da: Jelly il: 2017-11-15 10:34:45.378276 Its really good information, i like your blog post. Thanks for sharing 1024x768 Wallpapers

Inviato da: alice F taylor il: 2018-06-18 08:52:18.531704 During installation, Windows 10 will ask you for a product activation key. You will not be able to go ahead further without entering a valid key. If you want to test Windows or install Windows without entering your purchased license key, you can easily use the following generic windows 10 product key which will let you successfully install Windows with 30 days expiry. You can extend the expiry up to 90 days.

Inviato da: kerry il: 2018-07-04 15:23:05.436963 This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this..

Inviato da: National Blueberry Muffin Day il: 2018-08-18 14:23:20.327238 Thank you so much for sharing with us such an interesting post. keep doing a great work.

Inviato da: Carol il: 2018-09-01 13:18:26.292045 When I was using this code I was finding the error in regarding coding that is why I have changed my coding convention. UK Best Dissertation Writing Service also exist on Google map.

Inviato da: henrycarter139 il: 2018-02-26 11:23:01.685099 I like this post,And I figure that they having a great time to peruse this post,they might take a decent site to make an information,thanks for sharing it to me Broccoli

Inviato da: Broccoli il: 2018-04-02 17:11:45.386661 Provides multiple learning environment of International standard with holistic system of education at an affordable cost for the successful life of young generation. Paramedical College india
Hotel Management college in Dehradun
Agriculture college in uttarakhand
Best MBA College in Dehradun
Agriculture College in north india

Inviato da: renuka il: 2018-06-06 13:44:33.620429 Glad to visit your blog, I look forward to more good articles and I think we all like to thank so many good articles, blog to share with us.
Rashpal singh dhaliwal
Rashpal singh dhaliwal
Rashpal singh dhaliwal
Rashpal singh dhaliwal
Rashpal singh dhaliwal

Inviato da: dfdf il: 2018-07-16 13:46:34.134591 Thank you so much for sharing this information. color switch

Inviato da: color switch il: 2018-05-21 08:40:01.903609 These are really a superb showcases here I am glad to have a review of it and feel to roll on its steps for my benefit always Apple authorized service center delhi

Inviato da: dfd il: 2018-01-31 12:15:13.865287 Hi, great to see your website. I like the content and the research done behind every aspect of your blog. It looks great and very knowledgeable. Keep it up the good work. Hostpapa coupons deals

Inviato da: sharonfrankklin il: 2018-09-27 12:16:27.015859 With so many books and articles coming up to give gateway to make-money-online field and confusing reader even more on the actual way of earning money, Cabbage

Inviato da: Cabbage il: 2018-04-03 22:17:10.457395 The poster of the company is a bear on a unicycle, holding a beer and a burger. This is at the very start of their business but now Bareburger Menu is serving their sustainable fare all over the world. If “BareBurger Menu” has some new updates do tell us and all the readers of this website.

Inviato da: kiojo il: 2018-06-26 14:14:44.42189 I think you are right to say so. Your share is great, I found a lot of things in your post. Basketball Legends

Inviato da: Basketball Legends il: 2018-04-16 05:56:44.098324 This is truly an practical and pleasant information for all. Thanks for sharing this to us and more power HireWriters

Inviato da: HireWriters il: 2018-06-30 16:26:03.311333 Students learn best when they actively participate in the lesson or that they feel valued when teachers encourage them to share their knowledge with their peers.
best school in haryana
Boarding school in hisar

Inviato da: dfdf il: 2018-06-12 13:48:58.873238 I think you are right to say so. Your share is great, I found a lot of things in your post.

Inviato da: Basketball Legends il: 2018-04-16 05:53:05.455327 I agree with what you share. It will be very useful information for everyone. Hope your next posts are as well run 3 cool math

Inviato da: Anna Shetty il: 2018-05-29 04:59:25.242884 I’ve read some good stuff here. Definitely worth bookmarking for revisiting. I surprise how much effort you put to create such a great informative website. Cloves

Inviato da: Cloves il: 2018-04-02 14:40:50.496895 It is a good and amazing article. Your information is very useful for me and for others. thank you so much.

Inviato da: Hotmail Login il: 2018-06-09 20:23:48.773146 I quite like reading an article that can make people think. Also, thanks for allowing for me to comment!

Inviato da: good copywriting service il: 2018-06-30 16:25:02.223472 That's a good style, friend! Try yourself as a creative writer.You can definitely earn something!

Inviato da: color switch il: 2018-04-07 10:59:07.833216 This is a great little post with some valuable tips. I totally agree. The way you bring passion and engagement into the things you do can really change your outlook on live.

Inviato da: earn to die il: 2018-06-06 11:58:08.81684 thanks for the info, windows 7 product key for the various editions released. Below you will find Windows 7 Ultimate Product Key which are the latest updates and will work for you.

Inviato da: lio il: 2018-07-04 15:21:19.081912 The material and aggregation is excellent and telltale as comfortably. dissertation writing services sg private detectives

Inviato da: sg private detectives il: 2018-04-12 23:17:41.457865 Today the weather is quite beautiful. I like this. It makes me comfortable and works better. But I tried my best and try to finish the contest with a fierce determination to live up to the expectations of people. outlook entrar

Inviato da: eewg il: 2018-05-07 09:09:11.903145

Scrivi un commento:

Archivio