Как я открываю Google Maps для направлений с помощью координат на iPhone

Вот то, что я придумал ... также см. Ответ Сэма Шафрана. Этот ответ - вики сообщества, если есть какие-то проблемы, которые люди видят в коде и хотят обновить.

/// <summary>
/// A singleton queue that manages writing log entries to the different logging sources (Enterprise Library Logging) off the executing thread.
/// This queue ensures that log entries are written in the order that they were executed and that logging is only utilizing one thread (backgroundworker) at any given time.
/// </summary>
public class AsyncLoggerQueue
{
    //create singleton instance of logger queue
    public static AsyncLoggerQueue Current = new AsyncLoggerQueue();

    private static readonly object logEntryQueueLock = new object();

    private Queue<LogEntry> _LogEntryQueue = new Queue<LogEntry>();
    private BackgroundWorker _Logger = new BackgroundWorker();

    private AsyncLoggerQueue()
    {
        //configure background worker
        _Logger.WorkerSupportsCancellation = false;
        _Logger.DoWork += new DoWorkEventHandler(_Logger_DoWork);
    }

    public void Enqueue(LogEntry le)
    {
        //lock during write
        lock (logEntryQueueLock)
        {
            _LogEntryQueue.Enqueue(le);

            //while locked check to see if the BW is running, if not start it
            if (!_Logger.IsBusy)
                _Logger.RunWorkerAsync();
        }
    }

    private void _Logger_DoWork(object sender, DoWorkEventArgs e)
    {
        while (true)
        {
            LogEntry le = null;

            bool skipEmptyCheck = false;
            lock (logEntryQueueLock)
            {
                if (_LogEntryQueue.Count <= 0) //if queue is empty than BW is done
                    return;
                else if (_LogEntryQueue.Count > 1) //if greater than 1 we can skip checking to see if anything has been enqueued during the logging operation
                    skipEmptyCheck = true;

                //dequeue the LogEntry that will be written to the log
                le = _LogEntryQueue.Dequeue();
            }

            //pass LogEntry to Enterprise Library
            Logger.Write(le);

            if (skipEmptyCheck) //if LogEntryQueue.Count was > 1 before we wrote the last LogEntry we know to continue without double checking
            {
                lock (logEntryQueueLock)
                {
                    if (_LogEntryQueue.Count <= 0) //if queue is still empty than BW is done
                        return;
                }
            }
        }
    }
}
22
задан Aran Mulholland 10 October 2009 в 13:58
поделиться

2 ответа

Да, использовать MapKit невозможно. Вы можете попытаться сформировать запрос URL-адреса карт Google, содержащий ваше текущее местоположение и пункт назначения, который откроется в приложении Google Maps с указаниями.

Вот пример URL:

http://maps.google.com/?saddr=34.052222,-118.243611&daddr=37.322778,-122.031944

Здесь ' s как вы могли бы реализовать это в своем коде:

CLLocationCoordinate2D start = { 34.052222, -118.243611 };
CLLocationCoordinate2D destination = { 37.322778, -122.031944 };    

NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
                                 start.latitude, start.longitude, destination.latitude, destination.longitude];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
74
ответ дан 29 November 2019 в 03:24
поделиться

Надежное решение - создать контроллер представления с NIB, который включает UIWebView, а затем передать URL, который использует службы карт / направления Google. Таким образом, пользователь остается в приложении. Этот подход недостаточен при открытии веб-страницы, поскольку набор Apple не поддерживает масштабирование. Но в OS4, по крайней мере, пользователь может дважды нажать кнопку "Домой" и переключиться обратно в приложение.

1
ответ дан 29 November 2019 в 03:24
поделиться
Другие вопросы по тегам:

Похожие вопросы: