我有一个输入字段(我们称之为 $addressInput),我要求用户提供他的地址。
\n\n然后,我在后端使用该地址来检索该地址的纬度和经度。
\n\n对于某些地址,例如“214 Avenue du G\xc3\xa9n\xc3\xa9ral Leclerc, Eaubonne, France”,如果用户输入此地址,谷歌地图自动完成功能将在自动完成功能中向用户建议两个不同的地址下拉菜单。\n第一个(=建议 A)是“214 Avenue du G\xc3\xa9n\xc3\xa9ral Leclerc, Eaubonne, France”,第二个(=建议 B)是“214 Rue du G\xc3\xa9n” \xc3\xa9ral Leclerc,法国欧博讷”。
\n\n但是如果用户点击建议A,虽然输入填充的是“214 Avenue du G\xc3\xa9n\xc3\xa9ral Leclerc, Eaubonne, France”,但谷歌地图自动完成返回的真实formatted_address与建议A不一样,它是“214 Avenue de la Division Leclerc, 95160 Montmorency, France”。
\n\n为什么谷歌地图自动完成功能不直接在下拉列表中建议真实的 formatted_value ?为什么它在下拉列表中向用户显示地址,但在内部使用不同格式的地址?\n是否可以强制自动完成 API 在选择下拉列表中显示 formatted_address?\n在这种情况下,我会建议 A = " 214 Avenue de la Division Leclerc, 95160 Montmorency, France”(而不是“214 Avenue du G\xc3\xa9n\xc3\xa9ral Leclerc ...”)和建议 B =“214 Rue du G\xc3\xa9n\xc3\ xa9ral Leclerc,欧博讷,法国”
\n\n请在下面找到让我知道这一点的代码:
\n\nvar $addressAutoCompleteInput = $(\'.js-address-autocomplete-input\'); //this …Run Code Online (Sandbox Code Playgroud) 我的 Symfony 项目中有两个装置,一个 LoadSport.php 和一个 LoadCategory.php。
每个运动实例都有一个私有“类别”属性,它是类别的一个实例。我正在尝试检索数据库中已有的类别并将它们加载到体育赛事中(我选择了一些运动)。我按照另一个线程中的建议,按照官方在固定装置中使用容器(http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#using-the-container-in-the-fixtures)进行操作。
这是我的 LoadSport.php 代码:
class LoadSport implements FixtureInterface, ContainerAwareInterface
{
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
public function load(ObjectManager $manager)
{
$i = 0;
$em = $this->container->get('doctrine')->getManager();
$category = $em->getRepository("MyBundle:Category")->findOneById(1);
$names = array('SportA', 'SportB', 'SportC');
foreach($names as $name)
{
$sport = new Sport();
$sport->setName($name);
$sport->setCategory($category);
$manager->persist($sport);
}
$manager->flush();
}
public function getOrder()
{
return 2;
}
Run Code Online (Sandbox Code Playgroud)
我尝试调用一个单独的管理器来获取类别 n1,当我执行 php app/consoledoctrine:fixture:load 时,我收到以下错误消息:
[Symfony\Component\Debug\Exception\ContextErrorException] 可捕获的致命错误:传递给 MyBundle\Entity\Sport::setCategory() 的参数 …