Tuesday 29 May 2012

How to mock location on Android Emulator by using DDMS and KML file

Following are the steps:

1. Create a KML file like:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.x">
  <Placemark>
    <name>GE2ADT</name>
    <description>Attached to the ground. Intelligently places itself
       at the height of the underlying terrain.</description>
        <View><longitude>-88.03482</longitude><latitude>43.04186</latitude><range>750000</range><tilt>0</tilt><heading>0</heading></View><styleUrl>#red</styleUrl><Style><IconStyle><scale>0.3</scale></IconStyle><LineStyle><width>0.22</width></LineStyle></Style> <Point><coordinates>-88.03482,43.04186,0</coordinates></Point>
    </Placemark>
    <Placemark>
    <name>GE2ADT-1</name>
    <description>Attached to the ground. Intelligently places itself
       at the height of the underlying terrain.</description>
        <View><longitude>-88.03963</longitude><latitude>43.02743</latitude><range>750000</range><tilt>0</tilt><heading>0</heading></View><styleUrl>#red</styleUrl><Style><IconStyle><scale>0.3</scale></IconStyle><LineStyle><width>0.22</width></LineStyle></Style> <Point><coordinates>-88.03963,43.02743,0</coordinates></Point>
  </Placemark>
 </kml>

2. Launch the ddms from ...\tools.

3. In the ddms you can see in the left pane that there is no active device shown.

4. Launch you titanium Studio and select the project for which you want to test.

5. Click on run Configurations and in that select 'Google APIs for Android <version>' for 'Android APIs and click Run.

6. Wait for the emulator to start and then start Google Maps on it.

7. Now go to ddms and here now you can see the emulator processes in the left pane.

8. Now in the right pane go to tab 'Emulator Control'.

10. Scroll down and select tab KML.

11. Specify the location of the KML file.

12. In the table below you will the location coordinates uploaded form the KML file.

13. Scroll down little and click on the Play button.

14. Now go to Emulator where you should be able to see you location getting updated on the Google Maps.

Note: for a better idea add 5-6 location (Placemark) in the KML file.

No comments:

Post a Comment