Android MapView使用现有的GoogleMap API

时间:2012-06-27 13:33:23

标签: java android google-maps maps android-mapview

我搜索了SO和Google但没有找到任何答案。

我正在传递以下数据,需要在android中显示它。 http://maps.google.com/maps/ms?msid=214791092532835797516.0004bc20df4e3c6ddf92a&msa=0&ll=52.812827,-2.079865&spn=0.003761,0.011689&amp

目前我将其显示在webview中,其中IFrame是唯一的元素。但我真的需要在MapView中显示它。我创建了一个MapView并使其正常工作。我现在需要在MapView中显示数据,如上面的url所示。

虽然我可以看到lat / long值,是否可以获取自定义地图,并将其添加到MapView中?

1 个答案:

答案 0 :(得分:1)

尝试从URL获取KML文件,msid将匹配。

https://maps.google.com/maps/ms?msid=214791092532835797516.0004bc20df4e3c6ddf92a&msa=0&ll=52.812827,-2.079865&spn=0.003761,0.011689

KML文件的链接将是:https://maps.google.com/maps/ms?ie=UTF8&authuser=0&msa=0&output=kml&msid=214791092532835797516.0004bc20df4e3c6ddf92a

您必须解析KML以获取位置

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <name>Untitled</name>
  <description><![CDATA[]]></description>
  <Style id="style3">
    <IconStyle>
      <Icon>
        <href>http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png</href>
      </Icon>
    </IconStyle>
  </Style>
  <Style id="style2">
    <IconStyle>
      <Icon>
        <href>http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png</href>
      </Icon>
    </IconStyle>
  </Style>
  <Style id="style1">
    <IconStyle>
      <Icon>
        <href>http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png</href>
      </Icon>
    </IconStyle>
  </Style>
  <Placemark>
    <name>The Octagon</name>
    <description><![CDATA[<div dir="ltr">This is the description for the octagon</div>]]></description>
    <styleUrl>#style3</styleUrl>
    <Point>
      <coordinates>-2.081995,52.812881,0.000000</coordinates>
    </Point>
  </Placemark>
  <Placemark>
    <name>Sports centre</name>
    <description><![CDATA[<div dir="ltr">This is the description for the sports centre</div>]]></description>
    <styleUrl>#style2</styleUrl>
    <Point>
      <coordinates>-2.080439,52.812202,0.000000</coordinates>
    </Point>
  </Placemark>
  <Placemark>
    <name>Blackheath lane</name>
    <description><![CDATA[]]></description>
    <styleUrl>#style1</styleUrl>
    <Point>
      <coordinates>-2.072489,52.813522,0.000000</coordinates>
    </Point>
  </Placemark>
</Document>
</kml>

我想这会从URL获取位置,但我不确定如何轻松自定义android地图。

更新

解析KML文件,stackoverflow链接:How to draw a path on a map using kml file?