views:

246

answers:

2

Hi.

I have a button that launches the google maps app on my device via an intent. I want to be able to pass it a php page that generates a KML file.

I have done this on a website before using the googlemaps api in JS - but it doesn't seem to work on Android.

My php file is as follows;

<?php
echo '<kml xmlns="http://www.google.com/earth/kml/2"&gt;';
echo '<Placemark>';
echo '<name>Google Inc.</name>';
echo '<description>1600 Amphitheatre Parkway, Mountain View, CA 94043</description>';
echo '<Point>';
echo '<coordinates>-122.0841430, 37.4219720, 0</coordinates>';
echo '</Point>';
echo '</Placemark>';
echo '</kml>';
 ?>  

Launching with:

                    final Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,
                    Uri.parse("geo:0,0?q=http://website.com/kml_gen.php"));
                    startActivity(myIntent);

It launches maps, finds the file - but won't display it 'because it contains errors'.

Is this just not possible, or are there other ways to construct the intent that might work?

+4  A: 

Try setting the mimetype according to spec: application/vnd.google-earth.kml+xml

Put this on the first line

header('Content-type: application/vnd.google-earth.kml+xml');
alexanderblom
that's done it. Perfect. Thanks. I suspected it was related to mimetypes, but wasn't sure how to change them in this case.
arc
A: 

Hi! Thanks, this was very useful!

Is there a mechanism to send a kml file to the maps api? Or we need to construct it by hand?

Regards,

Sebastian