1

例如我有一个包含纬度和经度的 MySQL 数据库,我如何调用这些坐标以显示在地图中?任何人都可以帮助我吗?

4

1 回答 1

2

由于您的问题和信息有点不清楚,这些是我的假设:

  1. 我假设您已正确按照说明将 EGMap 扩展安装到您的 yii 应用程序中。
  2. 您想在所述坐标(纬度和经度)上放置一个标记。

示例代码:(请在注释为“// Get LatLong from table Location”的行中调整以适合您的数据库表和列)。将其直接放入您的视图文件示例中:protected/views/site/index.php

<!-- other html codes here -->
<div id="map-container">
<?php
// Get LatLong from table Location
$location=Location::model()->findByPk(1);
$latitude = $location->latitude;
$longitude = $location->longitude;

Yii::import('ext.gmap.*');

$gMap = new EGMap();
$gMap->setJsName('map');
$gMap->zoom = 10;
$mapTypeControlOptions = array(
    'sensor'=>true,
    'position'=> EGMapControlPosition::LEFT_BOTTOM,
    'style'=>EGMap::MAPTYPECONTROL_STYLE_DROPDOWN_MENU
);
// Map settings
$gMap->mapTypeControlOptions= $mapTypeControlOptions;
$gMap->setWidth(800);
$gMap->setHeight(600);
$gMap->setCenter($latitude, $longitude);

// Prepare icon
$icon = new EGMapMarkerImage("http://google-maps-icons.googlecode.com/files/gazstation.png");
$icon->setSize(32, 37);
$icon->setAnchor(16, 16.5);
$icon->setOrigin(0, 0);
// Prepare marker
$marker = new EGMapMarker($latitude, $longitude, array('title' => 'Gas Station','icon'=>$icon));
$gMap->addMarker($marker);

$gMap->renderMap();
?>
</div>
<!-- other html codes here -->
于 2012-05-18T05:11:16.570 回答